Issue with the disable button for an effect, help ples

posting about a difficulty chart… again.

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.

Update: I tried removing if plr.Character then and all i get is a plr.char.humanoid is not a valid member of

this was expected and thats the whole point of the if statement

however i have no clue how else to fix the problem

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

1 Like

Yeah aha it’s quite confusing… thats what happens when you’re at something for hours on end.

So the code first checks if the player has a character, simple as that

then it checks to see if the effect is enabled, and also if the player already has another effect applied

then it repeats every 0.1 seconds

hopefully that makes more sense

and yes it would make more sense to do it that way and im not sure why i did it, well, the way i did it

This is how I’d write it:

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.

enableButton.MouseButton1Down:Connect(function()
    effectsEnabled = true
end)
disableButton.MouseButton1Down:Connect(function()
    effectsEnabled = false
end)

You can edit values from the client now?

I would imagine that would have to be in the remote event

Also, the jump effect is one item you can purchase, and the speed effect is another one. the effects need to be separate from eachother

the script i am currently using works, it just doesn’t disable the effect until you respawn

So is your script supposed to be in the client or the server?

Also, if you want jump and speed to be separate, I’d just duplicate the code above and have one for speed and the other for walkspeed

The code i had was client sided, but i thought you could only edit boolean values and other values from the server, using a remote event

Ohhh I get it. thanks, trying it now

Yeah, it’s just a boolean value within the code. So it’s fine.

So I just realized

How would i make it

so that this part would give the correct effects enabled?

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

Yes but the script doesn’t know which effect to give and when

Okay. Let’s back up here.

When the enable button is pressed, you want the effects to be ON.

When the disable button is pressed, you want the effects to be OFF.

Is that true or am I not understanding it?

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.

I am incredibly sorry for the delay and mixup

Going back to my script, you’d put the effects here, where I placed the comments:

        if effectsEnabled == true then
            -- walkspeed and jump height are boosted
        else
            -- walkspeed and jump height are back to normal
        end

right but that would igve the player both effects instead of just the one they purchased

Any ideas on that? thats what im stumped upon

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.