so i am making a new game again and i have gems as a currency but the map is very big so i want some gems to give players speed instead but i don't know how, so here is my regular gem script, how do i change it to be what i want?
currency = "Gems" amnt = 60 debounce = false function onTouch(hit) if hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == false then if game.Players:findFirstChild(hit.Parent.Name) ~= nil then ThisPlayer = game.Players:findFirstChild(hit.Parent.Name) ThisPlayer.leaderstats:findFirstChild(currency).Value = ThisPlayer.leaderstats:findFirstChild(currency).Value + amnt script.Parent.Transparency = 1 script.Parent.CanCollide = false debounce = true wait(21) --NOTE Respawn time script.Parent.Transparency = 0 script.Parent.CanCollide = true debounce = false end end end script.Parent.Touched:connect(onTouch)
First off, there's a MUCH better way to get the player of a hit character.
game.Players:GetPlayerFromCharacter(character)
This will return the player of the character. In this case, hit.Parent would be the character.
game.Players:GetPlayerFromCharacter(hit.Parent)
Now, to give speed instead of currency. Of course, you would want to get rid of the script that adds currency to their player (I'm assuming that you made this script yourself and you can do this yourself). Then, you would need to get their humanoid.
local hum = hit.Parent:FindFirstChild("Humanoid")
This returns the Humanoid! Assuming you're smart enough to know how to edit this and get these values, and that you understand that "WalkSpeed" is a property of humanoid. Now, of course, you want to give it a duration. This is where you use spawn(). Using spawn(), you can run a code sample without halting the rest of the code. After they get the speedboost, you can do this:
spawn(function() hum.WalkSpeed = hum.WalkSpeed * 2 wait(10) hum.WalkSpeed = hum.WalkSpeed / 2 end)
This spawn will run the rest of the code, and increase the player's walkspeed for 10 seconds.