Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

i want to make my gems give speed instead of gems, how do i do that?

Asked by 4 years ago
Edited 4 years ago

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)
0
you probably will need to make another script that checks if, and how many gems of different types a players has.Otherwise you could have a player variable that your add to when a speed gem is picked up. Nickiel13 58 — 4y
0
??? dottsa_legend 16 — 4y
0
Just make it whenever you touch a gem the walkspeed of the player gets larger. Not that hard WideSteal321 773 — 4y
0
i tried that idiot!why do you think im here! dottsa_legend 16 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question