can anyone pls tell me why the value changes but the local script doesnt print?
server script:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local MoneyPrize = 5000
Players.PlayerAdded:Connect(function(player)
local LastPrizeClaim = Instance.new("IntValue",player)
LastPrizeClaim.Name = "LastPrizeClaim"
LastPrizeClaim.Value = 0
RunService.Heartbeat:Connect(function()
local character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local ChestZone = game.Workspace:WaitForChild("MapLayOut"):WaitForChild("VIPzone"):WaitForChild("DailyChest"):WaitForChild("ChestZone")
if HumanoidRootPart then
local distance = (HumanoidRootPart.Position - ChestZone.Position).Magnitude
-- if a day has passed since the last claim, give rewards
if distance < 9 and tick() - LastPrizeClaim.Value > 86400 then
LastPrizeClaim.Value = tick()
local Money = player:WaitForChild("leaderstats"):WaitForChild("Money")
OpenSound:Play()
Money.Value += MoneyPrize
end
end
end)
while true do
wait(1)
LastPrizeClaim.Value -= 1
end
end)
Based on the code provided, you’re creating LastPrizeClaim on the server and not parenting it to the workspace or leaderstats or anything, so it doesn’t exist on the client.
oh, my bad, totally missed that. Can you show the client-side code, how is it getting the IntValue object? Is it waiting for it to be created and sync to the client?
Are you certain the client side script is a LocalScript that’s running? I created a simplified version of your code and it works correctly:
ServerScriptService → Script
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local LastPrizeClaim = Instance.new("IntValue",player)
LastPrizeClaim.Name = "LastPrizeClaim"
LastPrizeClaim.Value = 0
while true do
wait(1)
LastPrizeClaim.Value -= 1
end
end)