Hello,
I’ve been testing a couple of things before moving on to a game and trying to understand certain things better and I’m on Raycasting. My only problem is that for some odd reason the ray would come from the world origin instead if the attachment I put inside of the tool.
I even tried to copy a tutorial to see if I could maybe fix it and replicate it on to my script but even that causes the ray to come from the origin of the world instead of the attachment like I set. I don’t know if I’m missing something or if I just keep repeating the same mistake.
- Script
local tool = script.Parent
local remoteFunction = script.RemoteFunction
tool.Activated:Connect(function()
script.Parent.Fire:Play()
local player = game.Players:FindFirstChild(tool.Parent.Name)
local rayOrigin = tool.Handle.RayOrigin.Position
local mousePos = remoteFunction:InvokeClient(player)
local distance = (mousePos - rayOrigin).Unit * 500
local rayCast = workspace:Raycast(rayOrigin, distance)
if rayCast then
print(rayCast.Instance)
end
end)
- Local Script
local remoteFunction = script.Parent.Script.RemoteFunction
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
remoteFunction.OnClientInvoke = function()
return mouse.Hit.Position
end