What do you want to achieve? Be simple and straightforward!
What I want to do is, if a player picks up an item, he will be given a random speed for a certain amount of time.
What is the problem? Attach screenshots/video if possible!
I tried something, but all those attempts ended in failure and errors.
What solutions have you tried so far? Have you looked for solutions on the Developer Hub site?
Honestly, I don’t remember the solutions anymore, I did it a long time ago (put it off for later, since this feature is on my game update list). Searched on DevHub - didn’t find it (if there is, I certainly don’t have eyes)
Anyway, hope someone can give links to tutorials or something.
I do not know why, but I could not do it, although I did things more complicated ;\
Humanoid.WalkSpeed = math.random(1,100) -- 16 is the default speed
wait(5) -- wait before returning back
Humanoid.WalkSpeed = 16 -- return it to the default
Do you mean like touches a part and it disappears or as a tool?
local tool = script.Parent
local humanoid = script.Parent:FindFirstChild("Humanoid")
local db = false
tool.Equipped:Connect(function()
if not humanoid or not db then return end
db = true
humanoid.WalkSpeed = math.random(1,100)
wait(5) -- cooldown
humanoid.WalkSpeed = 16
script:Destroy()
end)
local randomObject = Random.new(tick())
local _, character = nil, script.Parent or script.AncestryChanged:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = nil --Change this to point/refer to tool.
local used = false
tool.Equipped:Connect(function()
if used then return end
used = true
humanoid.WalkSpeed = randomObject:NextInteger(1, 100)
task.wait(5)
humanoid.WalkSpeed = 16
script:Destroy()
end)
You can use “math.randomseed()” instead, sometimes sessions run in the same seeds (which reduces the randomness of the numbers generated).
Hmm, strange, the script does not work and gives an error, as well as the code @KJry_s
I tried to change something, but it led to a bunch of errors. Maybe I’m doing something wrong ;/
local randomObject = Random.new(tick())
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent
local used = false
tool.Equipped:Connect(function()
if used then return end
used = true
humanoid.WalkSpeed = randomObject:NextInteger(1, 100)
task.wait(5)
humanoid.WalkSpeed = 16
script:Destroy()
end)