#help with raycasting for mmorpg

41 messages · Page 1 of 1 (latest)

ripe tree
#

Isn't that what it's supposed to do lmao

junior pewter
junior pewter
ripe tree
#

I'm not too experienced with all the other ray stuff

#

But workspace:Raycast() seems reliable

junior pewter
# ripe tree Maybe try workspace:RayCast()?

Here is the code for the cloning

local ClickPartTemplate = game.Workspace.ClickPart

game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()

local cloneClick = ClickPartTemplate:Clone()
cloneClick.Parent = game.Workspace

local torso = character:WaitForChild("Torso")
cloneClick.CFrame = torso.CFrame * CFrame.new(0, -0.3, 0)
local weld = Instance.new("Weld")
weld.Part0 = torso
weld.Part1 = cloneClick
weld.C0 = torso.CFrame:Inverse()
weld.C1 = cloneClick.CFrame:Inverse()
weld.Parent = cloneClick

end)

here is the code for the click becuase the clone is in workspace is that a problem?

game.Workspace.ClickPart.ClickDetector.MouseClick:Connect(function(Player)
script.Parent.Label.Text = Player.Name
end)

ripe tree
#

Wait bruh

#

You're only ever printing the name of the local player

#

Completely disregarding if you find another character or not

junior pewter
#

so what do i do

ripe tree
junior pewter
#

a bit

ripe tree
#

Or is this something you got from ai

junior pewter
#

both bro i did both i know a bit and i do a bit

ripe tree
#

Alright well

#

The player variable in your script is always going to be the local player

#

You're casting the ray but never actually find out if your ray hit another character

junior pewter
#

the welding i found a tutorial so i could learn and the i had to ask on how to print for the local script on this server

#

i did not use a ray

#

this is my old scripts

ripe tree
#

Then what is this

#

That's a ray lol

junior pewter
#

that was the new one im still deciding on which to use becuase when i try a ray it activates when you dont click the player and do i only want it to activate when you click the player

#

lol

ripe tree
junior pewter
#

if i cna fix this

why does it print player name when you click off the player (i put it in starterplayerscripts)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function performRayCast()

local ray = Ray.new(
    player.Character.Head.Position,
    (mouse.Hit.p - player.Character.Head.Position).unit * 100
)

local position = workspace:FindPartOnRay(ray, player.Character)

if player.Character then
    print(player.Name)
end

end

then i might use a ray

junior pewter
#

let me check

ripe tree
junior pewter
#

were would i put mouse.hit?

#

im still learning

#

here (mouse.Hit.p - player.Character.Head.Position).unit * 100 ?

junior pewter
#

right?

junior pewter
# ripe tree It just returns the BasePart your mouse is currently hovering over in 3d spacd

it got this

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function performRayCast()

local ray = Ray.new( 
    player.Character.Head.Position,
    (mouse.Hit - player.Character.Head.Position)
)

local position = workspace:FindPartOnRay(ray, player.Character)

if player.Character then
    print(player.Name)
end

end

mouse.Button1Down:Connect(performRayCast)

junior pewter
ripe tree
#
print(mouse.Hit)
junior pewter
ripe tree