✓ Accepted answer
I couldn't reproduce your problem efficiently, but I'll try my best.
I assume you have already put the script inside the part and it's a normal script.
There's a small mistake you made in the second line.
local h = workspace.Obj.Parent:FindFirstChild("Humanoid")
The Obj is a variable passed by the native function of the part Touched.
According to the API reference, the passed variable is BasePart.
It means that you don't need to type workspace. before typing Obj because Obj
is already a variable.
local h = Obj.Parent:FindFirstChildWhichIsA("Humanoid")
Also, sometimes(Just sometimes) using class finder is better for unexpected
names if you set the name of the player's Humanoid to a different name...
Using print is always a good practice to debug!
function onTouched(Obj)
local h = Obj.Parent:FindFirstChildWhichIsA("Humanoid")
if h then
workspace.Bob.HumanoidRootPart.Anchored = true
end
end
script.Parent.Touched:Connect(onTouched)
5 comments
Check if it's already anchored, and unanchor if it is. Otherwise, anchor it.
it is already unanchored
change line 2 to
local h = Obj.Parent:FindFirstChild("Humanoid")don't put it in a local script
to everyone who helped me figure this one out: Thank you so much! this was the last script I needed to finish my game.