Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

3 comments

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

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.

0

So try, "local player leaderstats.Coins.Value = leaderstats.Coins.Value + 10" instead.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.