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

Script is supposed to check if points = 4 then add one win. Why is it not working?

Script checks if player is on Red Team, if they are it checks if their points are 4 points if thats true it adds 1 win to them and makes a Frame visible.

local player = game.Players.LocalPlayer
local points = player:WaitForChild("leaderstats"):WaitForChild("Points")
local wins = player:WaitForChild("leaderstats"):WaitForChild("Wins")
local Team = game:GetService("Teams")

if player.Team.TeamColor == "Red Team" then
	if points.Value == 4 then
		wins.Value = wins.Value + 1
		player:WaitForChild("PlayerGui"):WaitForChild("RedTeamWins").Frame.Visible = true
	end
end

1 answer

the reason why it isnt working is because the if value only checks the conditions once, so unless you have a loop or something like that, it will not check, you can use .Changed so that the script runs whenever the value changes, or you can do either while true do with task.wait(), or while task.wait() do to make it loop forever (you can put in a number in task.wait() if you want it to check every so often. i cant really explain stuff so sorry about that

Always Trigger Option

local player = game.Players.LocalPlayer
local points = player:WaitForChild("leaderstats"):WaitForChild("Points")
local wins = player:WaitForChild("leaderstats"):WaitForChild("Wins")
local Team = game:GetService("Teams")

while true do
  if player.Team.Name == "Red Team" then
     If points.Value == 4 then
         wins.Value = wins.Value + 1
         player:WaitForChild("PlayerGui"):WaitForChild("RedTeamWins").Frame.Visible = true
     end
  end
  task.wait()
end

Change (In Seconds) How Long It Takes To Trigger Option

local player = game.Players.LocalPlayer
local points = player:WaitForChild("leaderstats"):WaitForChild("Points")
local wins = player:WaitForChild("leaderstats"):WaitForChild("Wins")
local Team = game:GetService("Teams")

while task.wait() do -- leave it blank if you want it to trigger any time it can, enter a number if you want it to wait (in seconds) then trigger
  if player.Team.Name == "Red Team" then
     If points.Value == 4 then
         wins.Value = wins.Value + 1
         player:WaitForChild("PlayerGui"):WaitForChild("RedTeamWins").Frame.Visible = true
     end
  end
end

Triggers When Value Is Changed Option

local player = game.Players.LocalPlayer
local points = player:WaitForChild("leaderstats"):WaitForChild("Points")
local wins = player:WaitForChild("leaderstats"):WaitForChild("Wins")
local Team = game:GetService("Teams")

points.Changed:Connect(function()
  if player.Team.Name == "Red Team" then
     If points.Value == 4 then
         wins.Value = wins.Value + 1
         player:WaitForChild("PlayerGui"):WaitForChild("RedTeamWins").Frame.Visible = true
     end
  end
end)

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