What does this error mean? And how do I work around it?

Hi! I am making a GUI where you enter a players user ID and it will give them 10 points.
When I click “Submit” it gives me the output

‘355661302’ Prints the user ID.image

I am using a Remote Function to do this.

Server script used to do the remote function stuff:

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")
local val = game:GetService("Lighting").Value.Value
local player = game:GetService("Players"):GetPlayerByUserId(val)

Event.OnServerEvent:Connect(function()
	player.leaderstats.Points.Value = player.leaderstats.Points.Value + 10
end)

The local script to fire the remote event:

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")
local player = script.Parent.Parent.TextBox.Text

script.Parent.MouseButton1Click:Connect(function()
	Event:FireServer(player)
	print(script.Parent.Parent.TextBox.Text)
	game:GetService("Lighting").Value.Value = script.Parent.Parent.TextBox.Text 
end)

Lighting is used to hold the player’s ID inside of an IntValue, I try and use this intvalue in the server script to give the points, i’m still unsure whether that’ll work or not.

Thanks!

(Ps. I might give late replys as it is 2 am and I’m going to sleep now.)

1 Like

local player = game:GetService("Players"):GetPlayerByUserId(val) returns a reference to a player object. If the code runs before the player connects to the game, the function will return nil, which it appears it may be doing in your case. If you move the player variable declaration into the OnServerEvent connection, it should be fine.

1 Like

I did it like this and it didn’t work, I don’t think I did it right?

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")
local val = game:GetService("Lighting").Value.Value

Event.OnServerEvent:Connect(function()
	local player = game:GetService("Players"):GetPlayerByUserId(val)
	player.leaderstats.Points.Value = player.leaderstats.Points.Value + 10
end)

Hello!

Have you made the leaderstats for the player yet?

If not then,
Put this code inside the server script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = leaderstats
	Points.Value = 0
end)



local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

Event.OnServerEvent:Connect(function(player)
	player:WaitForChild("leaderstats").Points.Value = player:WaitForChild("leaderstats").Points.Value + 10
end)

On server event needs player as parameter and the player isn’t passed through as an argument when firing the server

Also i just noticed that now,

Add “player” parameter to the server remote event.

Change:

Event.OnServerEvent:Connect(function()

To:

Event.OnServerEvent:Connect(function(player)
1 Like

add to that fire the remote event like this

Event:FireServer()

just dont include any arguments with the player as an argument

1 Like

The player argument is incorrect. Why are you using a value to indicate which player it is.

1 Like

Hello there again.

I decided to take a look at your script again and i saw some errors.

The client script is very wrong, You are trying to get the player from a text.

Copy this and paste it in the Server script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = leaderstats
end)



local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

Event.OnServerEvent:Connect(function(player)
	player:WaitForChild("leaderstats").Points.Value = player:WaitForChild("leaderstats").Points.Value + 10
end)

In the client:

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players:GetPlayerByUserId(script.Parent.Parent.TextBox.Text)
	Event:FireServer(player)
end)

You should always do a bit research before making a topic.

2 Likes

Yep, I used the one on the developer hub.

-- In 'ServerScriptService', add this into a script named 'PlayerSetup'
local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	-- Display an 'IntValue' on leaderboard
	local gold = Instance.new("IntValue")
	gold.Name = "Points"
	gold.Value = 100
	gold.Parent = leaderstats
end

-- Run 'onPlayerJoin()' when the 'PlayerAdded' event fires
game.Players.PlayerAdded:Connect(onPlayerJoin)
1 Like

I’ll see if this one works to.

If you are trying to get the player from UserId then i would recommend using my last reply scripts.

1 Like

Because when I type the player ID inside of the text box and hit submit it will put the ID inside of the IntValue and I can get the player through ID.

I don’t recommend putting the UserId inside the int value.

1 Like

Hi, I’ve been testing it and when I type numbers in the text box (player ID) it gives me (Local Player) the points. I have tested this with my friend, and when I typed his ID in the text box, it gave me the points. But when I type letters for example, it doesn’t give points to anyone.

So I can’t give points to the players. Any idea why it does this? By the way, it sends no output. :frowning:

(PS. I am using this in an admin panel, maybe thats why? I doubt it is the reason why.) image (The crossed out stuff is irrelevant, they’re just for tweening the GUIs ect.)

image

This is because the first parameter of the .OnServerEvent is the player who fired the event. To fix this just add another parameter to the function. Also, you can just do += 10 instead of typing the path again.

Event.OnServerEvent:Connect(function(player, receiver)
	receiver:WaitForChild("leaderstats").Points.Value += 10
end)
1 Like

Haha! I always forget that.
It’s new for me.

2 Likes

Life saver. Thanks a lot, it works perfectly.

1 Like