local Players = game:GetService("Players") local part = script.Parent local function onTouched(part) local playr = Players.LocalPlayer local player = Players:GetPlayerFromCharacter(part.Parent) if not player then return end print(player.leaderstats.Points.Value) end part.Touched:Connect(onTouched)
Explanation, the value of Points is set at 0, but when I use a tool to raise the value (similar to a simulator game), it still prints at 0. I even checked in the workspace, even if I SEE it is set at a number higher than 0, it still prints 0.
One likely candidate is that you're attempting to update the leaderstats value through a LocalScript. This does not work because of FilteringEnabled. In short, FilteringEnabled disallows LocalScripts from replicating anything to the server, except for a few rare cases in some Humanoid properties and Tools.
Most games get around this by the use of RemoteEvents. These allow direct communication between the client and the server. Using these, you can have the server update the leaderstats value for the player that fired the remote. I'll drop an example below.
Client Script
workspace.Part.Touched:Connect(function() game.ReplicatedStorage.Remote:FireServer() end)
Server Script
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(player) player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1 end)
Let me explain some things. First off, if you noticed at the top of the server script, you have to define the argument player, as RemoteEvents and RemoteFunctions will always send the player who called :FireServer()
or :InvokeServer()
as the first argument. And as a word of warning, do not send important data through a RemoteEvent/RemoteFunction. It is very easy for someone with malicious intent to modify the data sent through the remote or send their own :FireServer()
calls in order to trick your system.
Hoped this answered any questions you had. If you have any more, you can look up tutorials online or check the developer wiki.
use remote events. im assuming your editing the value on the client