So the full code is here in the two parts: Server and Local. I am trying to make a system that stores the Balance of the user, from the table, in a IntValue inside of their player in game.Players
then call it later to check if it has changed. If It has, send a Notification to the GUI via a local script. Whatever happens, the notification does not appear. If you need anything else, I'm happy to give you it. Thanks for reading and any potential help. This is for a game called Opix Islands on Roblox, I am not an expert nor a noob, I just got a bit stuck.
Server:
while true do
for i,v in game.Players do --this is the line with the error.
local tab = nil
for I,V in pairs(_G.GlobalData) do
if V.UserId == v.UserId then
tab = V
end
end
if not v.Bank then
newval = Instance.new("IntValue",v)
newval.Name = "Bank"
wait()
newval.Value = tab.Bank
else
if tab.Bank > v.Bank.Value then
print ("Greater than stored value")
local changedby = tab.Bank - v.Bank.Value
game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,false)
elseif tab.Bank < v.Bank.Value then
print ("Less than stored value")
local changedby = v.Bank.Value - tab.Bank
game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,true)--Player to send to,amount it has changed by,If it has gone down
end
end
end
wait()
end
And the Local script:
game.ReplicatedStorage.Notif.Return.OnClientEvent:Connect(function(Change,Down)
if Down == false then
local Notification = script.Parent.NotificationExample:Clone()
Notification.Name = "Notification"
Notification.Parent = script.Parent
Notification.Text = "Your Bank account balance has just increased by: £"..Change
print ("Bank account Increased by:"..Change)
Notification.Visible = true
print ("Notification should be visible")
wait(3)
Notification:Destroy()
print ("Notification should be gone!")
elseif Down == true then
local Notification = script.Parent.NotificationExample:Clone()
Notification.Parent = script.Parent
Notification.Name = "Notification"
Notification.Text = "Your Bank account balance has just decreased by: £"..Change
print ("Bank account decreased by:"..Change)
Notification.Visible = true
print ("Notification should be visible")
wait(3)
Notification:Destroy()
print ("Notification should be gone!")
end
end)
Here's a picture of the hierarchy, the event is in the replicated storage.
Many Thanks.