I am trying to make it where every time inround == false.
local function loadPlayerData(player)
local key = "Player_" .. player.UserId
local success, data = pcall(function()
return dataStore:GetAsync(key)
end)
if success and data ~= nil then
player.leaderstats.Cash.Value = data
end
end
-- Function to initialize leaderstats for a player
local function initializeLeaderstats(player)
-- Create leaderstats folder
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create Cash value
local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Value = 500
cash.Parent = leaderstats
end
-- Connect the functions to player events
game.Players.PlayerAdded:Connect(function(player)
initializeLeaderstats(player)
loadPlayerData(player)
end)
This is what makes the cash.
I made an inround value to check if the inround is false.
And if it is this script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InRound = ReplicatedStorage:WaitForChild("InRound")
local player = game.Players.LocalPlayer
if InRound.Value == false then
local msg = Instance.new("Message", workspace)
msg.Text = "Rewarded 150 Cash!"
local leaderstats = player:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Cash")
cash.Value = cash.Value + 150
else
error("Can't find the player cash!")
end
Your RewardHandler script is a local script inside ServerScriptService, so that will never run.
Scripts only run once when the game first loads or when they are first required. That if statement will only be checked once and never run again. You need to put it in a function that can be called or connected to an event so that it can check when the round starts and add the cash each time.
I added the local script in the StarterPlayerScripts.
Second I updated the code
local function checkRoundStatus()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InRound = ReplicatedStorage:WaitForChild("InRound")
local player = game.Players.LocalPlayer
if InRound.Value == false then
local msg = Instance.new("Message", workspace)
msg.Text = "Rewarded 150 Cash!"
local leaderstats = player:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Cash")
cash.Value = cash.Value + 150
else
error("Can't find the player cash!")
end
end
game.Players.PlayerAdded:Connect(function(player)
checkRoundStatus()
end)