So a little while back I created a sort of potion effect system where players can buy temporary boosts (speed or jump) but I’ve ran into a small problem.
When you first purchase the effect, it removes enough coins from your balance. It is set to disabled at first to not screw you up when you buy it. When you enable it, it starts working giving you the correct boost that you paid for. When you click disable again, however, it does not disable the effects until you die or reset.
It’s weird since resetonspawn is not enabled for the gui, and the script runs forever, in a while true do loop with minimal delay.
while true do
if plr.Character then
if toggle.Frame.EnableButton.Visible == true and plr.Character:WaitForChild("Humanoid").WalkSpeed == 16 then
if true then
plr.Character:WaitForChild("Humanoid").JumpHeight = 14.4
end
elseif toggle.Frame.EnableButton.Visible == true and toggle.Frame.DisableButton.Visible == false and not plr:WaitForChild("Character").Humanoid.JumpPower == 7.2 then
plr.Character:WaitForChild("Humanoid").WalkSpeed = 32
end
end
wait(.1)
end
I wonder if it’s because the character resets the humanoid when you die, but i have it so that when you reset with the effect still eneabled, you still have the effects you buy with your money.
Your if statements are a little difficult to understand for me. I have a question about it because I require a bit of clarity.
You’re checking if the EnableButton is visible in both if and else. May I ask why? Wouldn’t it make more sense to only check in if and not else? Because once the EnableButton is clicked, the effects should occur and then the DisableButton becomes visible. Then when you click the DisableButton, the DisableButton becomes invisible again and the EnableButton becomes visible.
Or is that not how you intend the script to work? Again, just trying to understand your code
local effectsEnabled = false --bool for effects on/off
while wait(.1) do -- neat little shortcut here for waits in while loops
if plr.Character then
toggle.Frame.EnableButton.Visible = not effectsEnabled
toggle.Frame.DisableButton.VIsible = effectsEnabled
if effectsEnabled == true then
-- walkspeed and jump height are boosted
else
-- walkspeed and jump height are back to normal
end
end
end
Then, whenever the EnableButton is clicked, I’d set the effectsEnabled button to true. Then do the opposite for the DisableButton.
That part sets the value to true or false depending on which button is clicked. Then we go back to the code here:
local effectsEnabled = false --bool for effects on/off
while wait(.1) do -- neat little shortcut here for waits in while loops
if plr.Character then
-- HERE if the value is true, the Disable button is shown. Otherwise, Enable button is shown
toggle.Frame.EnableButton.Visible = not effectsEnabled
toggle.Frame.DisableButton.VIsible = effectsEnabled
-- HERE it checks the value and gives effects accordingly
if effectsEnabled == true then
-- walkspeed and jump height are boosted
else
-- walkspeed and jump height are back to normal
end
end
end
So sorry for the delay! When the enable button is pressed, the effects will be ON. and when t he disable button is pressed, the effects will be OFF. However, my issue is, I have no idea how to make it so that the correct effect is applied when you turn the effects on and off, since only 1 is on at a time; either the speed boost effect, or the jump boost effect.
So you want the player to have two separate buttons, one for WalkSpeed and one for Jumping?
You would just make two separate scripts for each button. They’d basically be the same exact script as what’s above but one increases/decreases WalkSpeed while the other increases/decreases JumpPower.