Goal | When a player touches an egg, their leaderstat goes +1.
My scripts:
This script below spawns the eggs and destroys the egg if it is touched. The remoteEvent is just to trigger the GUI, but I won’t show that script
local eggs = game.ReplicatedStorage.Eggs
local spawns = game.Workspace.EggSpawns
while wait(2) do
local eggsTable = eggs:GetChildren()
local spawnsTable = spawns:GetChildren()
local randomEgg = eggsTable[math.random(1,#eggsTable)]
local randomSpawn = spawnsTable[math.random(1,#spawnsTable)]
local eggClone = randomEgg:Clone()
eggClone.Parent = game.Workspace.SpawnedEggs
eggClone.Position = randomSpawn.Position + Vector3.new(0,20,0)
eggClone.Anchored = false
eggClone.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.parent)
if plr then
game.ReplicatedStorage.FoundEgg:FireClient(plr,eggClone.Name)
eggClone:Destroy()
end
end)
end
Leaderstats, server script
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local eggs = Instance.new("IntValue")
eggs.Name = "Eggs"
eggs.Value = 0
eggs.Parent = leaderstats
end)
I tried adding a touched event in the leaderstats script but it didn’t work. I also tried making a remote event that was called in the first script and carried onto the second script but that also did not work
Help would be great, thank you!