I tried
local function epicvbuck(objecttouched ,toucher) print("whateva") objecttouched.Anchored = false end game.Players.LocalPlayer.Character.Humanoid.Touched:Connect()(epicvbuck)
this but in output whenever I touch something it reads "attempt to read a nil value"
it only prints "whateva" one time then stops I would also like to refer to the whole player not a single bodypart
I want it whenevera player touches any brick itll unanchor and fall i dont want to have to copy and paste a touched script into every single part in my game thanks in advance
If you want Touched
events, you have to check if the part you want touched is touching something. Then, you have to check if it's a humanoid, indicating it is a player.
This is what your code should look like:
script.Parent.Touched:Connect(function(hit) -- script.Parent is objecttouched, hit is toucher local humanoid = hit.Parent:FindFirstChild('Humanoid') -- check if humanoid if humanoid then -- if it is humanoid then do this print('whateva') script.Parent.Anchored = false end end)
The hit
is how you reference the object when using a Touched
event.
Hope I helped!
Here:
local Part = game.Workspace.Part --Getting the Part Part.Touched:Connect(function(hit) --Detecting if the Part is touched and running the function: hit local Humanoid = hit.Parent:FindFirstChild("Humanoid") --This gets the humanoid if Humanoid then --This detects if the thing that hit it is a Humanoid Humanoid.Health = 0 --Kills the player on touch end end)
This worked for me, I hope it works for you.
This should work havent tried it but hope it does it looks like you are a beginner scripter by the way you set up your script.
local function epicvbuck(Part) print("whateva") Part.Anchored = false -- Part Not Anchored end game.Players.LocalPlayer.Character.Humanoid.Touched:Connect(epicvbuck)