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
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