Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script not working like I want , how to make something unanchored when somebody hits it ?

Hello , I'm getting mad because I'm trying to do something but , I just don't know how to script ;-; , I thought that this script would have worked , welp it's working but like , I don't need to touch it that it will break :

function x(hit)
script.Parent.Anchored = false
script.Parent.GlassSound:Play()
script:remove()
end

script.Parent.Touched:connect(x)

I'm asking for your help , I want that when somebody hit the block , it's unanchoring . Thanks ;-;

1 comment

0

Edit: Put code in a code block

2 answers

function x(hit)
	if hit.Parent and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
		script.Parent.GlassSound:Play()
		
		for i,v in pairs(script.Parent:GetChildren()) do
			if v:IsA("BasePart") then
				v.Anchored = false
			end
		end
		
		script:Destroy()
	end
end

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(x)
	end
end

Line 2 will check to make sure it's actually a player that touched the table

Lines 5-8 will run through everything in the table model, if it's a part then it will unanchor it

And lines 15-16 runs through every part in the model, and line 17 waits for it to be touched

2 comments

0

Oh hi friend

0

hi

This should work:

script.Parent.Touched:Connect(function(hit) -- Make sure you use Connect instead of:
	-- connect
	if hit.Parent.Name == "Humanoid" then
		script.Parent.Anchored = false
		script.Parent.GlassSound:Play()
	else
		return hit
	end
end)

So you saying that it's working but you don't need to touch the brick for it to be called? If so than the code above should solve you problem.

1 comment

0

"if hit.Parent.Name == "Humanoid" then" It's impossible for a humanoid to touch something..

This discussion is preserved as it was. New answers, comments, and votes are closed.