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

Making sure it's only a player touching?

I have this script, and it works fine (for the most part) but when I touch it, it senses the hats also, how would I make it only take the characters name?

function onTouch(hit)
	if game.Workspace.Positions.First.Value == "" then
game.Workspace.Positions.First.Value = hit.Parent.Name
	elseif game.Workspace.Positions.Second.Value == "" then
		game.Workspace.Positions.Second.Value = hit.Parent.Name
			elseif game.Workspace.Positions.Third.Value == "" then
		game.Workspace.Positions.Third.Value = hit.Parent.Name
		wait(1)
		game.Workspace.Positions.Last.Value = true
end
end
script.Parent.Touched:connect(onTouch)

1 answer

✓ Accepted answer

Very simple solution, an if statement checking if the touch part's classname is not a hat, and it's parent has a humanoid (Just to make sure it's a character touching)

It could be done as follows:

function onTouch(hit)
	if not hit:IsA("Hat") and hit.Parent:findFirstChild("Humanoid") then
    	if game.Workspace.Positions.First.Value == "" then
			game.Workspace.Positions.First.Value = hit.Parent.Name
	    elseif game.Workspace.Positions.Second.Value == "" then
	        game.Workspace.Positions.Second.Value = hit.Parent.Name
	    elseif game.Workspace.Positions.Third.Value == "" then
	        game.Workspace.Positions.Third.Value = hit.Parent.Name
	        wait(1)
	        game.Workspace.Positions.Last.Value = true
		end
	end
end
script.Parent.Touched:connect(onTouch)

Hope it helps!

3 comments

0

Thanks!

0

The Hat check isn't needed. Hat's don't have Humanoids.

1

... I did the hat check so if the part is touched by a hat, it does not continue, because that's what he asked, and for the humanoid check, I am checking if the parent has a humanoid, not if hat has the humanoid, if I don't put the hat check, it will work if it's touched by a hat, which he doesn't want.

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