I’m creating a TD game and I want a Gui to appear when the player loses.
Its not working when a value hits 0 or less
local GUI = game.StarterGui.YouLost
script.Value.Value.Value.Changed:Connect(function(player)
if script.Value.Value.Value == -0 then -- Script.value is an object value in the script
local PlayerGui = player:WaitForChild("PlayerGui")
PlayerGui.GUI.Enabled = true
end
end)
script.Value.Value.Value.Changed:Connect(function(player)
if script.Value.Value.Value <= 0 then -- Script.value is an object value in the script
local PlayerGui = player:WaitForChild("PlayerGui")
PlayerGui:WaitForChild("YouLost").Enabled = true
end
end)
You literally defined your variable in startergui, and the == -0 should be replaced with is lower or equal to 0
Is this supposed to be a Value Object of some sort? If so, then you’re referencing the parameter incorrectly (Or player unless if you’ve referring to an ObjectValue)
Also you art getting the StarterGui
Try this:
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Value = script.Value.Value.Value
Value.Changed:Connect(function(NewValue)
if NewValue <= 0 then -- Script.value is an object value in the script
PlayerGui.GUI.Enabled = true
end
end)