I want to create a button that when pressed, resets the stats of the player until they press it again.
Here’s the script that keeps the player’s jump power up to date with a value I set for it:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
chr:WaitForChild("Humanoid").UseJumpPower = true
while wait(0.1) do
chr:WaitForChild("Humanoid").JumpPower = plr.StuffThatIsntInLeaderstats.JumpMultiplier.Value
end
end)
end)
Here’s what I’ve tried scripting for the button: (Doesn’t work)
local button = script.Parent
local yes = false
local player = game.Players.LocalPlayer
local jumpMultiplier = player:WaitForChild("StuffThatIsntInLeaderstats").JumpMultiplier
button.MouseButton1Click:Connect(function()
local InitialValue = jumpMultiplier.Value
if not yes then
jumpMultiplier.Value = 0
yes = true
else
jumpMultiplier.Value = InitialValue
yes = false
end
end)
You need to change the value from a server script for the mutliplier change to take effect, you can use remote events but it will be unsafe so you should instead make the script a server script.
InitialValue is being set to 0 right before the stat is reset to its actual value (which isn’t 0, probably). Declare InitialValue before the mouse click connection and only set it in the first branch of your if loop.
local button = script.Parent
local yes = false
local player = game.Players.LocalPlayer
local jumpMultiplier = player:WaitForChild("StuffThatIsntInLeaderstats").JumpMultiplier
local InitialValue = 0
button.MouseButton1Click:Connect(function()
if not yes then
InitialValue = jumpMultiplier.Value
jumpMultiplier.Value = 0
yes = true
else
jumpMultiplier.Value = InitialValue
yes = false
end
end)
Doesn’t work, again I’m pretty sure part of the problem is in how Im updating the jumpPower of the player constantly every 0.1 seconds. Although I don’t know how to fix this so that it still works.
Make your mouse connection fire a RemoteEvent that makes the server do the jumpMultiplier code because right now it’s client-side only and your first script will only ever read what the server sees, which never changes because the mouse code only affects each player’s client’s version of the JumpMultiplier.
You know you can control the jump power from the button script instead of having to use IntValues, and worse, a while loop that does nothing.
local Players = game:GetService("Players")
local button = script.Parent
local isJumpPowerOnDefault = false
local player = Players.LocalPlayer
local jumpMultiplier = player:WaitForChild("StuffThatIsntInLeaderstats").JumpMultiplier
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.UseJumpPower = true
humanoid.JumpPower = 50 -- Change this to whatever you want the default jump power to be
-- Or, humanoid.JumpPower = jumpMultiplier.Value
end)
end)
button.Activated:Connect(function()
if isJumpPowerOnDefault then
player:WaitForChild("Humanoid").JumpPower = 0
isJumpPowerOnDefault = false
else
player:WaitForChild("Humanoid").JumpPower = jumpMultiplier
isJumpPowerOnDefault = true
end
end)