Why does my speedup power not work?

So im trying to make a script that grants players a random superpower upon pressing a button

i tried making the superpower as an item that gives you the powers when you equip it (i mean it appears in the backpack but you cant physically hold it)

the problem is that i made a code that should speed you up once you “equip” the speed superpower but for some reason it does not work

local character = player.Character -- Gets the Players Character
local humanoid = character:FindFirstChild("Humanoid") -- Gets the Humanoid

player.Backpack.speed.Equipped:Connect(function() -- speed is the name of the superpower
	if humanoid then -- Checks if its the Humanoid
		humanoid.WalkSpeed = 32 -- Doubles the Speed of the Player
	end
end)

player.Backpack.speed.Unequipped:Connect(function()
	if humanoid then -- Checks if its the Humanoid
		humanoid.WalkSpeed = 16 -- The Normal Speed of The Player
	end
end)

It does appear in the backpack but once you use it it doesn’t change anything

Can the problem be cause of the scripts location?
the current location of the script is in Replicated Storage in the speed tool and its a local script

if not then i really have no idea why isnt it working

basically i just want to make a speed coil that doesn’t show up in your hand

hopefully yall can point me in the right direction :wink:

3 Likes

why not make a script inside the tool object then access the tool object within the script e.g.

local tool=script.Parent --gets tool object
2 Likes

This right here is the problem.
Scripts cant run in ReplicatedStorage

Try parenting it onto the tool or in StarterPlayerScripts

4 Likes

the speed power is paranted to the tool already or did you mean some other tool?

2 Likes

The same tool. Also local scripts don’t work in Workspace only normal scripts. Try changing it to normal scripts and setting the RunContext to client
image

2 Likes

but the script is not int the worspace. its in replicated storage in an additional file

try this script

local player = game:GetService("Players").LocalPlayer
local character = player.Character -- Gets the Players Character
local humanoid = character:FindFirstChild("Humanoid") -- Gets the Humanoid

local tool = script.Parent

tool.Equipped:Connect(function() -- speed is the name of the superpower
	if humanoid then -- Checks if its the Humanoid
		humanoid.WalkSpeed = 32 -- Doubles the Speed of the Player
	end
end)

tool.Unequipped:Connect(function()
	if humanoid then -- Checks if its the Humanoid
		humanoid.WalkSpeed = 16 -- The Normal Speed of The Player
	end
end)

Hmm, still doesn’t work
ok lets start from the beginning. Where do i store items so they dont automatically appear in the players backpack, but appear there only after certain criteria is met?

Well you need to clone it into your backpack which means after you press the button it will clone it to your character. The ReplicatedStorage is just there for you to keep a main copy so that you can clone it multiple times.


Here I added a localscript so that when you press the button it will give you the power.

Here is the File if you want to see it working in action
Help11.rbxl (59.9 KB)

(I wasn’t sure why creating a tool for me didn’t work out so well so I just copied the sword from roblox lol)

To clarify, localscripts do not run anywhere other than StarterPlayerScripts, StarterCharacterScripts, StarterGui, or the player’s Backpack.

local character = player.Character or player.CharacterAdded:Wait()

LocalScript will run in tools equipped by the player, as they will be under the player’s character

Correct, but only because it was originally in the backpack, as per the runtime.

The whole code operates on this system
i have a table with powers
the powers themselves are just tools, with LocalScript in it, that are originally stored in replicated storage

then when the player presses the specific button on the keyboard (E for example) it takes a random power from the table, makes a clone of it and stores it into players backpack

in my example its the speed power that speeds you up when you equip it

it does everything right except for the script in the tool. It does store the power in the players backpack but when equipped, it does nothing

Hmm that is very strange, it worked fine for me on my end.


I changed the speed to 64 to make it easier to see the speed difference

I changed the code so that it matches what you said (Pressing E instead of pressing a text button).


What about putting the tool in the player in Workspace instead of Players.Backpack:


My test code(placed in StarterPlayerScripts)

local Button = script.Parent;
local RS = game:GetService("ReplicatedStorage");
local player = game:GetService("Players").LocalPlayer;
local UIS = game:GetService("UserInputService");

UIS.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then return; end
	
	if input.KeyCode == Enum.KeyCode.E then
		local powerClone = RS.Powers.speed:Clone(); -- clones the tool from the replicatedstorage
		powerClone.Parent = player.Character; -- gives to the player
		player.Character.Humanoid:UnequipTools()
		print("E has been pressed and given the tool!")
	end
end)

-- Tool in workspace version, uncomment below and comment above to test
--[[ <--- Remove this to test
UIS.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then return; end
	
	if input.KeyCode == Enum.KeyCode.E then
		local powerClone = RS.Powers.speed:Clone(); -- clones the tool from the replicatedstorage
		powerClone.Parent = workspace:FindFirstChild(player.Name); -- gives to the player in workspace
		player.Character.Humanoid:UnequipTools()
		print("E has been pressed and given the tool in workspace!")
	end
end)
--]]--

Ahhh nevermind, I found the problem, you need a handle part
image

This is because the player has nothing to use/hold.

Here I tested it not working after I deleted the handle part

This is why I was able to make it work with the sword from roblox in the toolbox

So just add in a part to the tool, make it invisible/transparent then you should be good

Do you think there is anyway to grant the player the speed power without him needing to hold anything?

Well yes, you can just directly give the speed buff instead of making it a tool

So it would look something like

local UIS = game:GetService("UserInputService");
local player = game:GetService("Players").LocalPlayer;
local character = player.Character -- Gets the Players Character
local humanoid = character:FindFirstChild("Humanoid") -- Gets the Humanoid

UIS.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then return; end
	
	if input.KeyCode == Enum.KeyCode.E then
		humanoid.WalkSpeed = 32;
	end
end)

If you want to add a timer just use something like task.wait()

local UIS = game:GetService("UserInputService");
local player = game:GetService("Players").LocalPlayer;
local character = player.Character -- Gets the Players Character
local humanoid = character:FindFirstChild("Humanoid") -- Gets the Humanoid

UIS.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then return; end
	
	if input.KeyCode == Enum.KeyCode.E then
		humanoid.WalkSpeed = 32; -- give speed
		task.wait(4) -- wait 4 seconds
		humanoid.WalkSpeed = 16; -- reset back
	end
end)

Add UserInputService, detect if a key is being pressed (your choice) and ensure the player has the tool in his backpack, and when input has ended then make it normal again

The problem is that I want the player to get 1 random power. That’s why I store them in the power folder and also have a dedicated table from where it takes 1 random power and gives it to the character

So I can’t just change their speed once they press the button.

If I recorrect my question:

How to make a speed coil that doesn’t show up in your hand when you equip it, but gives its speed effect