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

HELP! Touched Function not Working Properly?

when i press the play button. it automatically turns the parts green without needing to touch the base part.

script.Parent.BasePart.Touched:connect(function() for i,v in pairs(script.Parent:GetChildren()) do v.BrickColor = BrickColor.new("Bright green") end end)

4 answers

local function onTouch(hit)

pairs(script.Parent:GetChildren()) do v.BrickColor = BrickColor.new("Bright green") end 

end

script.Parent.BasePart.Touched:connect(onTouch)

game.Workspace.mapStorage.map.King.Torso.Touched:connect(onTouch)

--I think this should work

the reason it is doing that is because if any part touches it then it will change so I recommend doing this

function Touch(hit)
	if hit.Parent == hit.Parent:FindFirstChild("Humanoid") then
	if (human~= nil) then -- checks if it's a player
for i,v in pairs(script.Parent:GetChildren()) do v.BrickColor = BrickColor.new("Bright green")
			 end 
		end
	end
end

script.Parent.Touched:connect(Touch)

2 comments

0

Thanks.

0

it worked?

Local B = script.Parent.BasePart

Local function boom() script.Parent.BrickColor = ("whatevercoloryouwant")

end

B.Touched:connect(boom)

Check this out!

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then --check if it's an humanoid
		for i,v in pairs(script.Parent:GetChildren()) do
			v.BrickColor = BrickColor.new("Bright green")
		end
	end 
end)

If it works, please mark this answer as the correct one!

And as always, good scripting!

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