local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local char = player:WaitForChild("Character")
local hrp = char:FindFirstChild("HumanoidRootPart")
mouse.Button1Down:Connect(function()
local ray = Ray.new(hrp.Postion, Vector3.new(0,-1,0))
local hit, position = game.Workspace:FindPartOnRay()
if hit then
print("Hello")
end
end)
Im kind of beginner in roblox scripting. So i’ve got an error in this thing.
Sorry if i did any careless mistakes my brain is not in a good shape today.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player.Character
local char = player.Character
local hrp = char:FindFirstChild("HumanoidRootPart")
mouse.Button1Down:Connect(function()
local ray = Ray.new(hrp.Position, Vector3.new(0,-1,0))
local hit, position = game.Workspace:FindPartOnRay(ray)
if hit then
print("Hello")
end
end)
For first, you cant do
local char = player:WaitForChild("Character")
Character is property of player, not a child. Just wait until it appears. Second, you misstyped word “Position”, you typed “Postion”
local ray = Ray.new(hrp.Postion, Vector3.new(0,-1,0))
Last thing, function
local hit, position = game.Workspace:FindPartOnRay(ray)
The character is not a child of the player. Instead, it’s a property of the Player that refers to the character model in the workspace. If you want to wait for the character to load. There is an event called CharacterAdded which you can use to wait for the character.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local char = player.Character or player.CharacterAdded:Wait() -- When you do "or" it checks whether the first value is nil or not. If nil, it will check for player.CharacterAdded:Wait()
local hrp = char:FindFirstChild("HumanoidRootPart")
mouse.Button1Down:Connect(function()
local ray = Ray.new(hrp.Postion, Vector3.new(0,-1,0))
local hit, position = game.Workspace:FindPartOnRay()
if hit then
print("Hello")
end
end)
On top of that, you’re not using the FindPartOnRay method correctly. The function requires the ray as the first argument:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local char = player.Character or player.CharacterAdded:Wait() -- When you do "or" it checks whether the first value is nil or not. If nil, it will check for player.CharacterAdded:Wait()
local hrp = char:FindFirstChild("HumanoidRootPart")
mouse.Button1Down:Connect(function()
local ray = Ray.new(hrp.Postion, Vector3.new(0,-1,0))
local hit, position = game.Workspace:FindPartOnRay(ray)
if hit then
print("Hello")
end
end)