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
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
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
Oh I see what you mean now.
In that case you need to disable the equip animation. There are multiple ways to do this but my solution is to get the Animate script first from your player and replacing it with the updated Animate script. It’s a bit of a long process but here is the project file if you want to see it.
Help11.rbxl (66.6 KB) (I updated this file again, there were some errors in the code)
Here it is working in action:
To get the Animate script you have to play the game first then go into your player then you will find it there
Then place it somewhere so you can clone this (preferrably in Replicated Storage if possible, I just put mine in StarterPlayerScripts to make it easier for me) and disabling it
Then you need another script to tell it to clone it to your player ( in this case its the ReplaceAnimateScript )
Then put this code in ReplaceAnimateScript
local RS = game:GetService("RunService");
local Player = game.Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait(); -- Wait for the character to spawn
local Humanoid = Character:WaitForChild("Humanoid");
Character:WaitForChild("Animate"):Destroy(); -- Destroy the default animations
local Tracks = Humanoid:GetPlayingAnimationTracks(); -- Get all playing animations from our character
for i, thistrack in pairs(Tracks) do -- Stop and destroy all animations that are playing
thistrack:Stop();
thistrack:Destroy();
end
local NewAnimScript = script.Animate -- Reference and parent the new script
NewAnimScript.Parent = Character;
NewAnimScript.Enabled = true;
And then in the Animate script that you took, find Line 734 and comment it out so that its unable to play the hold animation
Right now there isn’t a way to directly access the Animate script that is cloned when the player joins (Roblox won’t allow it for some reason ) so we have to replace it instead.
Also I would like to mention that this only works when player is added the first time, which means it will stop working after the player resets character/respawns.
I improved it so when you reset, it will replace the Animate script again
in ReplaceAnimateScript:
local player = game.Players.LocalPlayer;
local character = player.Character or player.CharacterAdded:Wait(); -- Wait for the character to spawn
local humanoid = character:WaitForChild("Humanoid");
character.Animate:Destroy(); -- Destroy the default animations
local newAnimScript = script.Animate -- Reference and parent the new script
newAnimScript.Parent = character;
newAnimScript.Enabled = true;
player.CharacterAdded:Connect(function(chara: Model)
chara.Animate:Destroy(); -- Destroy the default animations
newAnimScript.Parent = chara;
end)
Dude thank you very much for your time and help
i decided to settle with speed as a characters characteristic (After getting the speed power they can sprint by pressing s certain button)
you helped a lot
thanks
You can just put the Animate script in StarterCharacterScripts and it will automatically override roblox assigning a regular Animate script to player characters (it needs to be called ‘Animate’). You don’t need to manually replace everytime via script