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

How do I make Coconuts in my game give both Coconuts and Experience?

Asked by 4 years ago

So I am making a new game with a Coconuts currency and a level system but I want Coconuts to give both Coconuts and Experience (I already have the level system) but how do I make one Coconut give both? Here is my script:

currency = "Coconut"    
amnt = 1
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.Sound:Play()
            script.Parent.Transparency = 1
            script.Parent.CanCollide = false
            debounce = true
            wait(15)
            script.Parent.Transparency = 0
            script.Parent.CanCollide = false
            debounce = false
            end
        end
    end


script.Parent.Touched:connect(onTouch)
0
How do you keep track of experience in your game? MegaManSam1 207 — 4y

1 answer

Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago

Here you go!

currency = "Coconut"  
currency2 = "Experience"
amnt2 = 1--Change this to the amout you want  
amnt = 1
debounce = false        

    function onTouch(hit)
        if hit.Parent:findFirstChild("Humanoid") and debounce == false then
            if game.Players:findFirstChild(hit.Parent.Name) then
            ThisPlayer = game.Players:findFirstChild(hit.Parent.Name)
            local Cononuts = ThisPlayer.leaderstats:FindFirstChild("Coconuts")
        local XP = ThisPlayer.leaderstats:FindFirstChild("Experience")
        XP.Value = XP.Value + amnt2
    Coconuts.Value = Coconuts.Value + amnt
    script.Sound:Play()
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    debounce = true
    wait(15)
    script.Parent.Transparency = 0
    script.Parent.CanCollide = false
    debounce = false

            end
        end
    end


script.Parent.Touched:connect(onTouch)

I hope this helps you! Tell me if it dosen't work and your error if it not work. Bye!

Ad

Answer this question