Help Fix My Script!

Hey Scripters, Can you help me fix my script. It doesn’t work for some reason. Thanks!

game.Players.PlayerAdded:Connect(function(player)
	game.Players.LocalPlayer.UserId == "id" then
		player.leaderstats.Tickets.Value = player.leaderstats.Tickets.Value + 1000000000
	else
end)
1 Like

You forgot to add a if statement.

game.Players.PlayerAdded:Connect(function(player)
	if player.UserId == "id" then
		player.leaderstats.Tickets.Value = player.leaderstats.Tickets.Value + 1000000000
	end
end)
2 Likes

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

1 Like

Ok thank you and @LINDON55 for helping me! But @LINDON55’s script didn’t work…

2 Likes

The player argument is passed with game.Players.PlayerAdded, so replace game.Players.LocalPlayer with player

1 Like

@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?

1 Like

Please could you include all of your code as it makes it easier for us to help you.

2 Likes

did any error pop up in output?

2 Likes

Sure I’m trying to make to make a certain player get a certain amount of point here is my place:

Edit: My friend is helping me test his id is 1172203233,

Its hard to identify the problem since my place isn’t organized.

I have uploaded my place found anything?

1 Like
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)
3 Likes

I would suggest making a baseplate and testing the code there

1 Like

Did u put it in a script? not a local script! And did you put it in workspace or serverscriptstorage?

1 Like

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)

1 Like

Is the leaderstats script also in workspace or serverscriptservice? And is it a normal script? I’m on my phone so i can’t really check it

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.

2 Likes

2 outputs found.
1 2

1 Like

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.

1 Like

Show us the leaderstats script maybe too? Does it even exist?

1 Like

My leaderstats script: @alliedoeihoialt @PseudoPerson


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) ```
1 Like

Is it in a normal script or local script?

1 Like