The following will be if you want the leaderstats to be reflected to the entire server:
– SERVER SCRIPT –
local players = game:GetService("Players")
local replStorage = game:GetService("ReplicatedStorage")
local levelEvent = replStorage:WaitForChild("LevelEvent")
players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
local levelStat = Instance.new("IntValue")
levelStat.Parent = leaderstats
levelStat.Parent = 0
local coinsStat = Instance.new("IntValue")
coinsStat.Parent = leaderstats
coinsStat.Value = 0
end)
levelEvent.OnServerEvent:Connect(function(player, Price)
player:WaitForChild("leaderstats"):WaitForChild("Level").Value += 1
player:WaitForChild("leaderstats"):WaitForChild("Coins").Value -= Price
end)
The server script includes leaderstats itself.
– LOCAL SCRIPT –
local Price = 200
local replStorage = game:GetService("ReplicatedStorage")
local levelEvent = replStorage:WaitForChild("LevelEvent")
script.Parent.MouseButton1Click:Connect(function(plr)
if plr:WaitForChild("leaderstats"):WaitForChild("Level").Value >= Price then
levelEvent:FireServer(Price)
Price += 25
end
end)
Organisation:
