My goal here is to put the RayPart 5 units in front of the local characters HumanoidRootPart, relative to their orientation using CFrame:ToWorldSpace function, however, I get the error "attempt to index nil with 'HumanoidRootPart'" and I'm not really sure what it means. I think it means that nil is trying to read HumanoidRootPart, but that can't be, as the part does exist. The error is on line 11. LocalScript:
game.Loaded:Wait() -- To prevent loading issues local player = game.Players.LocalPlayer local char = player.Character local rayPart = game.ReplicatedStorage.RayPart:Clone() rayPart.Parent = workspace game.ReplicatedStorage.GiveAbilityToTransfurm.OnClientEvent:Connect(function() spawn(function() while wait() do rayPart.CFrame = char.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(0, 0, 5)) end end) end)
I am not very experienced with CFrame, so this could be a very simple fix.
local char = player.Character or player.CharacterAdded:Wait()
try this instead of : local char = player.Character
player.CharacterAdded:Wait() is waiting until is character loaded, "Attempt to index with HumanoidRootPart" means, the character doesnt had time to load and script doesnt knew what HumanoidRootPart is.
Instead of game.Loaded:Wait() you could use
player.CharacterAdded:Wait()