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

for i,v loop not completely working as intended?

Statue is a part. Im trying to loop through the players and seeing if they have a value called RedTeam and if they do, then they can touch this "Statue" with there sword and when the sword touches it it will plus 1 a value, but the only thing as that I dont know what is wrong with this?

local Statue = script.Parent.Parent

for i,v in pairs (game.Players:GetPlayers()) do
	local RedTeam = v:FindFirstChild("RedTeam")
	Statue.Touched:Connect(function(hit)
		if hit.Name == "Handle" and RedTeam then
			script.Parent.Value = script.Parent.Value + 1
			wait(3)
		else
			print("hey idot this is your own statue")
		end
	end)	
end

2 comments

0

Did you check that the player has redteam?

0

Yes I did. The bool value appears in the player

1 answer

✓ Accepted answer
script.Parent.Touched:Connect(function(part)
	if part.Name == "Handle" then
		local player = game.Players:GetPlayerFromCharacter(part.Parent.Parent)
		if player then
			local RedTeam = player:FindFirstChild("RedTeam")
			if RedTeam then
				script.Parent.Value = script.Parent.Value + 1
            	wait(3)
        	else
           		print("hey idot this is your own statue")
			end
		end
	end
end)

This should solve your script I think. Tell me if you still have any problems.

1 comment

0

Thank you!

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