#help with raycasting for mmorpg
41 messages · Page 1 of 1 (latest)
yes it works but when you click another player it does not
it only works when you click yourself
Maybe try workspace:RayCast()?
I'm not too experienced with all the other ray stuff
But workspace:Raycast() seems reliable
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)
Wait bruh
You're only ever printing the name of the local player
Completely disregarding if you find another character or not
so what do i do
Do you know scripting
a bit
Or is this something you got from ai
both bro i did both i know a bit and i do a bit
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
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
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
Yk you can use Mouse.Hit for this right
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
Why not just use mouse.Hit
let me check
It just returns the BasePart your mouse is currently hovering over in 3d spacd
were would i put mouse.hit?
im still learning
here (mouse.Hit.p - player.Character.Head.Position).unit * 100 ?
but remove the .p
right?
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)
there an error on line 6 tho " Workspace.CraftingBlkBelt.PlayerDisplayStats:6: invalid argument #2 to 'new' (Vector3 expected, got CFrame)"
Literally, replace all code in your "performRayCast()" function with this:
print(mouse.Hit)
then it will just give me cordes right?
Nope