I have a question to something that happened to me a few times while coding in Roblox Studio: I have a simple example of the problem:
local Value = Instance.new("NumberValue")
Value.Value = 10
while true do
print(Value.Value)
end
Until now everything has been working, but if I add or remove the Value of "Value" it still prints 10. It's the same thing when I want to save the value in a Datastore it only takes the Value that was there when "Value" was created. Here's my code for saving player data.
game.Players.PlayerRemoving:Connect(function(player)
local money = player:WaitForChild("money")
local DataStoreService = game:GetService("DataStoreService")
local MoneyStore = DataStoreService:GetDataStore("PlayerMoney")
local success, errorMessage = pcall(function()
MoneyStore:SetAsync(player.UserId, money.Value)
end)
if not success then
print(errorMessage)
end
print("saved "..player.Name.."'s money! It is $"..money.Value)
end)
I don't understand your problem but I think that you're using a LocalScript, please use a server script to make changes. If want the player, then there are parameters that can give you the player who touched, triggered, added or removed. If you're using UserInputService then you should use a RemoteEvent or RemoteFunction.