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

Why is the script triggering the remote event if it doesn't meet an "if" requirement?

Hey. I have a script that triggers a remote event if a player's value is false and a player's team is not a specific team. The problem is that if the value is false and the player is part of that specific team the remote event is still triggered. Help? Script:

for i, v in pairs(Players) do
		
		
		local Team = game:GetService("Teams")["Police"]
		
		if Players[i].Robbing.Value == false and Players[i].Team ~= Team then
			game.ReplicatedStorage.ShowRobberyGUI:FireClient(Players[i])
			Players[i].Robbing.Value = true
		end
	end

1 answer

Idk what the issue is, but maybe us changing it a little will fix it:

for i, v in pairs(game.Players:GetChildren()) do
    local Team = game:GetService("Teams")["Police"]
    if v.Robbing.Value == false and v.Team ~= Team then
        game.ReplicatedStorage.ShowRobberyGUI:FireClient(v)
		v.Robbing.Value = true
	elseif v.Robbing.Value == true and v.Team == Team then
		warn("Player Already set")
    end
end

Let me know if this helps you ~nevan

2 comments

0

You need to explain the changes. (saying this before a mod sees it)

0

@Pupppy44 don't worry, next time I'll be faster

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