Hello! I had somebody join me in my simulator and once they joined. Everytime I click on a point button, they get the point instead of me. Vice versa, if they join me, I get the point instead of them! Please help me!
local DS = game:GetService("DataStoreService")
local RS = game:GetService("ReplicatedStorage")
local ColorData = DS:GetDataStore("Colors")
local GetColor = false
local colorevent = RS.Color
local player = game.Players
player.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = 'leaderstats'
leaderstats.Parent = plr
local ColorPoints = Instance.new("IntValue")
ColorPoints.Name = "🎨 Color"
ColorPoints.Value = 0
ColorPoints.Parent = leaderstats
-- [Rarity] --
colorevent.OnServerEvent:Connect(function(play, Points)
if GetColor == false then
GetColor = true
play.leaderstats["🎨 Color"].Value += Points
task.wait(1)
GetColor = false
end
end)
--------
local Data
local success, errormsg = pcall(function()
Data = ColorData:GetAsync(plr.UserId.."- Color")
end)
if success then
print("Loaded")
plr.leaderstats["🎨 Color"].Value = Data
else
warn(errormsg)
end
end)
player.PlayerRemoving:Connect(function(plr)
local Succes, errormessage = pcall(function()
ColorData:SetAsync(plr.UserId.."- Color", plr.leaderstats["🎨 Color"].Value)
end)
if Succes then
print('Success!')
else
print("Error, data not saved!")
warn(errormessage)
end
end)
game:BindToClose(function(p)
for _, playr in pairs(game.Players:GetPlayers()) do
local ID = "Player_"..playr.UserId
local success, errormsg = pcall(function()
ColorData:SetAsync(ID, p.leaderstats["🎨 Color"].Value)
print("Yay, Saved!")
end)
end
end)