game.Players.PlayerAdded:Connect(function(player)
if player.UserId == "id" then
player.leaderstats.Tickets.Value = player.leaderstats.Tickets.Value + 1000000000
end
end)
game.Players.LocalPlayer won’t work in server scripts. Also, the UserId “id” doesn’t exist. UserIds are always numbers. Assuming you’re trying to give yourself the tickets, just replace that line with if player.UserId == 107756428 then
@Wrvel May I ask what you’re trying to do? it’s kind of hard to help you if you don’t explain what you need fixed. What error does it have? What do you need it to do?
local PlrId= 1172203233 -- PlayerID of the player you want to give points too
game.Players.PlayerAdded:Connect(function(player)
if player.UserId == PlrId then
player.leaderstats.Tickets.Value = player.leaderstats.Tickets.Value + 1000000000
end
end)
Here is my place feel free to see why it won’t work because I have no idea myself. The Tickets and the scripts I used are all there. Please help me! TestMyPlace.rbxl (171.0 KB)
assert(script.ClassName == "Script", "This code must be run from a script!")
local specialUserId = 00000000 --Enter your special user id here
game.Players.PlayerAdded:Connect(function(player)
--You shouldn't change leaderstats on the client (from a local script) so you SHOULD have this in a Script and use the player variable.
if player.UserId == specialUserId then
--These two lines check to make sure the needed things exists
assert(player.leaderstats, script.Name..": \"leaderstats\" not found!")
assert(player.leaderstats.Tickets, script.Name..": \"Tickets\" not found in \"leaderstats\"!")
player.leaderstats.Tickets.Value = player.leaderstats.Tickets.Value + 1000000000
else
end
end)
You can take out the assert statements if it works. They will just help other dev forum users help if something goes wrong.
Edit: Didn’t see that you didn’t complete the if else statement. Added end after else.
Try copying and pasting the code again. I added a keyword. You also need to add the leaderstats folder, it’s not automatically there for you. You might want to send the full code if you want help with that part.
local playerData = DataStoreService:GetDataStore("PlayerData")
local function onPlayerJoin(player) -- Runs when players join
local leaderstats = Instance.new("Folder") --Sets up leaderstats folder
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local tickets = Instance.new("IntValue") --Sets up value for leaderstats
tickets.Name = "Tickets"
tickets.Parent = leaderstats
local completed = Instance.new('Folder')
completed.Name = 'completed'
completed.Parent = player
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
-- Data exists for this player
tickets.Value = data
else
-- Data store is working, but no current data for this player
tickets.Value = 0
end
end
local function onPlayerExit(player) --Runs when players exit
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.leaderstats.Tickets.Value) --Saves player data
end)
if not success then
warn('Could not save data!')
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit) ```