So i have a tool that multiplies player speed by 25%. But when i unequip it, It does not set back to the regular speed. Any way to fix this?
Code
local amt = 5
script.Parent.Equipped:Connect(function(mouse)
if script.Parent.Parent:FindFirstChild("Humanoid")~=nil then
script.Parent.Parent:FindFirstChild("Humanoid").WalkSpeed*=amt
end
end)
function Unequipped()
if script.Parent.Parent:FindFirstChild("Humanoid")~=nil then
script.Parent.Parent:FindFirstChild("Humanoid").WalkSpeed/=amt
end
end
script.Parent.Unequipped:Connect(Unequipped)
script.Parent.Equipped:Connect(function(mouse)
if script.Parent.Parent:FindFirstChild("Humanoid")~=nil then
script.Parent.Parent:FindFirstChild("Humanoid").WalkSpeed = 80
end
end)
script.Parent.Unequipped:Connect(function()
if script.Parent.Parent:FindFirstChild("Humanoid")~=nil then
script.Parent.Parent:FindFirstChild("Humanoid").WalkSpeed = 16 -- 16 x 5 = 80
end
end)
One big issue… I have a 2x speed gamepass with this. So this won’t work if the user has 2x speed. Because it just sets it to the roblox default. And not 32 (when user has 2x speed)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local GamepassId = 69420 -- replace 69420 with the gamepass Id
local Humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local player
script.Parent.Equipped:Connect(function(mouse)
if humanoid ~= nil then
player = Players:GetPlayerFromCharacter(humanoid.Parent)
humanoid.WalkSpeed = 80
end
end)
script.Parent.Unequipped:Connect(function()
if humanoid ~= nil then
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) then
humanoid.WalkSpeed = 32
else
humanoid.WalkSpeed = 16
end
end)
The script itself has to multiply and divide the speed so it can work without wasting lines. And there is no set speed, The amt is how much it will multiplty/divide
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamepassId = 69420 -- replace 69420 with the gamepass Id
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local player
local amt = 5
script.Parent.Equipped:Connect(function(mouse)
if humanoid ~= nil then
player = Players:GetPlayerFromCharacter(humanoid.Parent)
humanoid.WalkSpeed *= amt
end
end)
script.Parent.Unequipped:Connect(function()
if humanoid ~= nil then
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
humanoid.WalkSpeed *= 2
else
humanoid.WalkSpeed /= amt
end
end)