Unanchor a block by touching it

image

I am not a scripter but I want to make a horror game where when you touch an invisible block, a model/part goes unanchored and plays a sound or whatever.

Please can you tell me whats wrong with this script, thank you.


local function onTouch(hit)
    if (hit.Parent:FindFirstChild("Humanoid")) then
       workspace.JoeMama.Anchored = false
    end
end

workspace.JoeMama.Touched:Connect(onTouch)
2 Likes

your if statement doesn’t have a then to run the condition.
Try

if hit.Parent:FindFirstChild("Humanoid") then
also, :findFirstChild() is deprecated, I recommend you use :FindFirstChild()

1 Like

This doesn’t appear to be working, I think @Krythoptic said basically the same thing to change and I don’t think that works either.

The “then” on line 2 has a red line underneath it

I forgot to add another bracket at the end, copy it again and try it now.

I am really bad at scripting (so i dont understand a lot of things), I added it at the end but I am not sure it is in the right place as it still doesn’t work

When testing, did you click on the part to see if it is unanchored?

It is anchored, is that an issue?

No, when you test select the part and check its properties to see if the script unanchored it

image

I don’t think the script unanchored it also this is in output from the script

oh thats an old issue that got fixed just now

make sure the code is in the same script and its in a server script not a local script

local function onTouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		workspace.JoeMama.Anchored = false
	end
end

YOURPARTPATHHERE.Touched:Connect(onTouch)

Removing parenthesis from the if statement won’t change anything, it’ll work the same.

Might as well not get Lua confused with other languages

It is in a Script and I really think I am being dumb here because I still can’t get it to work

Unfortunately, you’re mistaken. Lua will still understand this.

local part = "foo"

if (part == "foo") then
	print("true")
end

I tested this and it prints out true.

1 Like

Where is the script placed? Use a server script and place it in workspace

Im not saying it wouldnt work, I just said it might get confused with other languages.

Can you show us the explorer hierarchy (where your parts and scripts are placed)?

Not sure that’s relevant since other people from other languages won’t feel a difference.