I want players to get coins / points when the round ends.
I have made the scripts and the leader stats work, but players would not get the points.
coin giver script
local Gui = game.StarterGui.RoundSystemGUI
if Gui.TextLabel.Text == "Round Ending" then
wait(0.5)
game.Players:WaitForChild("leaderboard").Points += 10
end
Leader stats script
game.Players.PlayerAdded:Connect(function(Player)
if Player then
local leaderboard = Instance.new("Folder")
leaderboard.Name = 'leaderstats'
leaderboard.Parent = Player
local Points = Instance.new("IntValue")
Points.Name = 'Coins'
Points.Parent = leaderboard
Points.Value = 0
end
end)
First of all, you shouldn’t reference StarterGui in scripts as all the StarterGui elements are replicated to all of the players’ PlayerGuis. Also, you cannot make Server-Sided changes from LocalScripts, therefore you’re going to need a RemoteEvent. Instead, you should do this in a LocalScript, and make the script’s parent the Gui that you referenced, alongside making a RemoteEvent called “AddPoints” in ReplicatedStorage.
LocalScript:
local Gui = script.Parent
local event = game:GetService("ReplicatedStorage"):WaitForChild("AddPoints")
if Gui.TextLabel.Text == "Round Ending" then
wait(0.5)
event:FireServer(10)
end
New Server-Script in ServerScriptService:
local event = game:GetService("ReplicatedStorage"):WaitForChild("AddPoints")
event.OnServerEvent:Connect(function(player, points)
if -- find a way to check if the round ending, if the round is ending then
player:WaitForChild("leaderstats").Points += points
end
end)
Be careful as exploiters can fire RemoteEvents at any time, which is why you need server-side protection.
Do keep in mind that while @walshuk has the correct solution here, checking text on the client is bad practice. You should really be handling all of your game’s logic on the server (including checking when the round is over and giving points), and only using the client for graphical interface and other interaction components.