Number value increasing when it's not supposed to be

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Create a power system for how hard you hit the projectile

  2. What is the issue? Include screenshots / videos if possible!
    The boolean value increases when you click the decrease button and vice versa
    https://gyazo.com/4103709928d26df3e4c918a051e80259

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Changing the server script instead of using a number to decide how much power needs to be added/decreased to either be negative or positive

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local scripts

Increase

local button = script.Parent
local plr = game.Players.LocalPlayer

button.Activated:Connect(function()
	if plr.Power.Value < 11 then
		game.ReplicatedStorage.RemoteEvents.Value.Power:FireServer(1)
		print(plr.Power.Value)
		button.Parent.Power.Text = plr.Power.Value
	else
		button.Parent.Power.Text = 10
	end
end)

Decrease

local button = script.Parent
local plr = game.Players.LocalPlayer

button.Activated:Connect(function()
	if plr.Power.Value > 1 then
		game.ReplicatedStorage.RemoteEvents.Value.Power:FireServer(-1)
		print(plr.Power.Value)
		button.Parent.Power.Text = plr.Power.Value
	else
		button.Parent.Power.Text = 1
	end
end)

Server script

game.ReplicatedStorage.RemoteEvents.Value.Power.OnServerEvent:Connect(function(plr,amount)
	plr.Power.Value = plr.Power.Value+amount
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

Certainly an odd occurance…
It is possible that you are trying to set the text too soon after telling the server to update the value.

If you add another script contained within the TextLabel (Power), that contains the following code

local plr = game.Players.LocalPlayer
plr:WaitForChild("Power"):GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = plr.Power.Value
end)

and remove

print(plr.Power.Value)
button.Parent.Power.Text = plr.Power.Value

from the other scripts,

does it have any effect on the issue?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.