I really do not know how to explain this but I will try:
Let us say that you have an item that gives you 2 points every time you click
Once you reached 10 it no longer gives you points
Now let us say that you have an item that gives you 6 points every time you click
If you click twice it will exceed the limit and continues to give you points
Script:
local plr = game.Players.LocalPlayer
script.AddStrength.OnServerEvent:Connect(function(player)
if player.leaderstats.Strength.Value == script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
else if player.leaderstats.Strength.Value < script.Capacity.Value then
game.Workspace.MainEvent.Disabled = false
end
end
end)
You said you had the value set to 10, I just wondered how you managed to set it to that value.
For troubleshooting the script you could put a print(player.leaderstats.Strength.Value) and print(script.Capacity.Value) statement in the if and elseif sections to see what it is at that point.
If you want to stop the count of MainEvent and disable it when the Strength value is equal or higher than capacity then you shouldnât check if it is only equal to. Because your value goes above capacity itâs not going to be equals to capacity if it overpasses the limit. Try this:
local plr = game.Players.LocalPlayer
script.AddStrength.OnServerEvent:Connect(function(player)
if player.leaderstats.Strength.Value >= script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
else if player.leaderstats.Strength.Value < script.Capacity.Value then
game.Workspace.MainEvent.Disabled = false
end
end
end)
So you want strength to be set as capacity once is above the limit?
local plr = game.Players.LocalPlayer
script.AddStrength.OnServerEvent:Connect(function(player)
if player.leaderstats.Strength.Value >= script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
player.leaderstats.Strength.Value = script.Capacity.Value
else if player.leaderstats.Strength.Value < script.Capacity.Value then
game.Workspace.MainEvent.Disabled = false
end
end
end)
It worked! But when I tested this on an Item that gives more than the limit (Lets say 15) it still exceeds it but if you click again it deducts it back to the limitâŚ
I could try making the limit a bit bigger and only make items that gives points which is a multiple of that limit⌠Should I wait for a better solution or just do this?
What about if you add Changed event on the Strength value and then change it to the limit? Try this:
local plr = game.Players.LocalPlayer
player.leaderstats.Strength.Changed:Connect(function()
if player.leaderstats.Strength.Value >= script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
player.leaderstats.Strength.Value = script.Capacity.Value
end
end)
script.AddStrength.OnServerEvent:Connect(function(player)
if player.leaderstats.Strength.Value >= script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
player.leaderstats.Strength.Value = script.Capacity.Value
else if player.leaderstats.Strength.Value < script.Capacity.Value then
game.Workspace.MainEvent.Disabled = false
end
end
end)
Instead of âplayer.leaderstatsâ type âplr.leaderstatsâ on the changed event.
plr.leaderstats.Strength.Changed:Connect(function()
if plr.leaderstats.Strength.Value >= script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
plr.leaderstats.Strength.Value = script.Capacity.Value
end
end)
local plr = game.Players.LocalPlayer
plr:WaitForChild("leaderstats",10)
plr.leaderstats.Strength.Changed:Connect(function()
if plr.leaderstats.Strength.Value >= script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
plr.leaderstats.Strength.Value = script.Capacity.Value
end
end)
script.AddStrength.OnServerEvent:Connect(function(player)
if player.leaderstats.Strength.Value >= script.Capacity.Value then
game.Workspace.MainEvent.Disabled = true
player.leaderstats.Strength.Value = script.Capacity.Value
else if player.leaderstats.Strength.Value < script.Capacity.Value then
game.Workspace.MainEvent.Disabled = false
end
end
end)