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

Why is my script not adding currency to the player that found the easter egg?

Asked by 5 years ago
Edited 5 years ago

So i made a easter egg but if you found it i wanted to give the player coins. But I can't figure out how to do it. so I experimented a little bit but it dosen't seem to work :(

local player leaderstats.Coins.Value = Coins.Value + 10

btw i have a clickdetector before so i don't really need to specify which player clicked it.

edit whole cript

local debounce = false 
script.Parent.ClickDetector.MouseClick:Connect(function()
if debounce == false then debounce = true
script.Parent.Size = Vector3.new(3,3,3) else
debounce = false
script.Parent.Size = Vector3.new(4,4,4) debounce = true
            if debounce == true then debounce = false
            script.Parent.Sound:Play()
            game.StarterGui.EasterEgg1.EasterEggText.Visible = true
            wait(3)
            game.StarterGui.EasterEgg1.EasterEggText.Visible = false
            game.Workspace.Wut:Destroy()
        end
            end
               end)

and yes i'm bad at scripting xd

0
okay I'm unsure what this script is that you just posted?? "player" isn't localized in one area you put leaderstats.coins.value then in another you put coins.value i am very confused DesiredRep 75 — 5y
0
Make sure this is in a server script because of filtering enabled, and also, I noticed something weird, as DesiredRep said, for the first one, you specified that "Coins" was a child of "leaderstats", but the second time, you didn't. Knineteen19 307 — 5y
0
So try, "local player leaderstats.Coins.Value = leaderstats.Coins.Value + 10" instead. Knineteen19 307 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Based on your one line of code, I'll assume you're using a local script? You can actually do this in a server script.

Script

local debounce = true
local easteregg = workspace.EasterEgg

easteregg.Touched:Connect(function(hit)
if debounce == false then return end
debounce = false
    local check = hit.Parent:FindFirstChild("Humanoid")
    if check ~= nil then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local Coins = player.leaderstats.Coins.Value
        player.leaderstats.Coins.Value = Coins + 10
        easteregg:Destroy()
    end
debounce = true
end)

You'll need to change the workspace.EasterEgg to whatever the name and location of the item is, and the event being fired if it's not a Touched Event. The debounce prevents the function from being played multiple times

Ad

Answer this question