I'm trying to make an obby but I am not grasping how to change one player's leaderstats value without changing others. This is my code:
local DataStore2 = require(1936396537)
local defaultValue = 1
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if char == player.Character then
local stage = player.leaderstats.Stage
if stage.Value == script.Parent.Name - 1 then
stage.Value = script.Parent.Name
local stageDataStore = DataStore2("Stage",player)
stageDataStore:Increment(1,defaultValue)
end
end
end
end)
There is no error, however, it is changing every player's stage instead of just the one who touched the spawn at the next stage.
(This is how I set up DataStore2:)
local stageDataStore = DataStore2("Stage", player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
Stage = Instance.new("IntValue", leaderstats)
Stage.Name = "Stage"
Stage.Value = defaultValue
local function stageUpdate(updatedValue)
Stage.Value = stageDataStore:Get(updatedValue)
end
stageUpdate(defaultValue)
defaultValue is equal to 1, btw, and this is all set up once a player joins.

6 comments
I'm not sure if the .Touched script is causing the problem? Maybe it has to do with your DataStore2.
How is your data set up? It may be a problem with that. Also, line 12 can cause problems. Change that to if stage.Value == tonumber(script.Parent.Name) - 1 then
Oops, Roger beat me to it lol
Okay, so I just edited the post to show how I set up DataStore2
also, thanks for the suggestion, Despayr
So I just deleted the datastore lines, and it works fine. I am not sure what to do about it though