Powerup script not working

  1. What do you want to achieve? I want to be able to go 2.1 speed whenever I walk with the tool but to be disabled whenever I click again or I unequip the tool
    EDIT: I want to also make it so when I double tap w it unequips the tool

  2. What is the issue? Whenever I walk it makes me the regular walk speed and not the 2.1 walk speed
    EDIT: I don’t know how to script the double-tap w to unequip

  3. What solutions have you tried so far? I’ve looked for solutions but nothing has helped!
    EDIT: I cant find anything related to it too!

enabled = false
local Tool = script.Parent;
local dancer = nil
local player = game.Players.LocalPlayer



function onActivated()


	--This will check if it is enabled and then either start dancing or stop dancing
if enabled == false then
	local humanoid = Tool.Parent:FindFirstChild("Humanoid")
	local torso = Tool.Parent:FindFirstChild("Torso")

	dancer = humanoid:LoadAnimation(Tool.dance)
	Tool.DanceObject.Value = dancer
	dancer:Play()
	Tool.dancepart.Position = player.Character.Head.Position
	Tool.dancepart.SongLoop:Play()
	enabled = true
	speed = player.Character.Humanoid.WalkSpeed
	player.Character.Humanoid.WalkSpeed = 2.1
	repeat 
	wait(100)
	Tool.dancepart.Position = player.Character.Head.Position
	until enabled == false
	
else
	dancer:Stop()
	dancer:remove()
	Tool.dancepart.SongLoop:Stop()
	enabled = false
	player.Character.Humanoid.WalkSpeed = speed
end
end

function onUnequipped()
		dancer:Stop()
		dancer:remove()
		Tool.dancepart.SongLoop:Stop()
		enabled = false
		player.Character.Humanoid.WalkSpeed = speed
end

Tool.Activated:connect(onActivated)
Tool.Unequipped:connect(onUnequipped)

whenever I walk whilst dancing I walk at the regular walk speed and not 2.1 walk speed

2 Likes

You never declared speed as a variable here. Add it as a variable before the function

enabled = false
local Tool = script.Parent;
local dancer = nil
local player = game.Players.LocalPlayer

local speed = nil --declare speed

function onActivated()

	--This will check if it is enabled and then either start dancing or stop dancing
if enabled == false then
	local humanoid = Tool.Parent:FindFirstChild("Humanoid")
	local torso = Tool.Parent:FindFirstChild("Torso")

	dancer = humanoid:LoadAnimation(Tool.dance)
	Tool.DanceObject.Value = dancer
	dancer:Play()
	Tool.dancepart.Position = player.Character.Head.Position
	Tool.dancepart.SongLoop:Play()
	enabled = true
	speed = player.Character.Humanoid.WalkSpeed
	player.Character.Humanoid.WalkSpeed = 2.1
	repeat 
	wait(100)
	Tool.dancepart.Position = player.Character.Head.Position
	until enabled == false
	
else
	dancer:Stop()
	dancer:remove()
	Tool.dancepart.SongLoop:Stop()
	enabled = false
	player.Character.Humanoid.WalkSpeed = speed
end
end

function onUnequipped()
		dancer:Stop()
		dancer:remove()
		Tool.dancepart.SongLoop:Stop()
		enabled = false
		player.Character.Humanoid.WalkSpeed = speed
end

Tool.Activated:connect(onActivated)
Tool.Unequipped:connect(onUnequipped)
1 Like

Hmm, Its not working. Im walking with the emote on and I am still walking with the regular walk speed and not walking slow and for extra measures i changed the speed to 0 and it still doesnt work. Would ya mind giving me the script with the variable if i made any mistakes?

1 Like

Is the render property set to false?

1 Like

but the line you are quoting is literally declaring speed as a variable and setting it to the walkspeed

1 Like

declaring it as a variable would be doing

local speed = player.Character.Humanoid.WalkSpeed

But in his script,

local speed

was never mentioned, making it a variable that wasn’t declared.

There’s a certain amount of reasons as to why your script won’t work. Let’s break it down now:

  1. You don’t have a variable named ‘speed’. I could be wrong, but I don’t see that anywhere in the code provided
  2. Your code needs to be more organized. If something isn’t easy to read, how do you expect to find out the problem with it?

If this doesn’t solve your issue, then I don’t think I’ll be of any help. Hope it does though, so good luck!

I cant find anything to help me, thanks for the help though! Dont worry I can scrap the tool emote thing and go with /e instead.

apparently it was the sprint system that i had in game! i fixed it now

the local keyword, as the name suggests, only makes an identifier local to the scope, it does not declare variables. speed = player.Character.Humanoid.WalkSpeed may not be ideal in terms of style as it declares speed as a global, but it has no problems whatsoever in terms of syntax

abc = 123
print(abc)

will work completely fine