Got instance from player.Name

Hello developers, i trying to make a event what gives a clicks to player, but there is problem i got a instance from player.Name why? I Calling from LocalScript.

Event Script:

local replic = game:GetService("ReplicatedStorage").Events

replic.Click.OnServerEvent:Connect(function(player)
	-- ok

	-- debug
	-- no debug

	game:GetService("Players")[player].leaderstat.Points.Value += game:GetService("Players")[player].Values.toGive.Value * 2
end)

Calling script:

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	game:GetService("ReplicatedStorage").Events.Click:FireServer(player.Name) 
	return --print(player.Name)	
end)

Error:

Someone pls help!

On the line,

game:GetService("Players")[player].leaderstat.Points.Value

you did [player], which is an instance. you’ll have to do [player.Name].

Or instead just do player.leaderstats.Points.Value
So script becomes

local replic = game:GetService("ReplicatedStorage").Events

replic.Click.OnServerEvent:Connect(function(player)
	-- ok

	-- debug
	-- no debug

	player.leaderstat.Points.Value += player.Values.toGive.Value * 2
end)

This is just easier and more efficient

Cause in the first script you’ve sent when you said OnServerEvent, the first parameter is player which is the client where you got the message from.

Add a new parameter called player2 and that will be Player.Name.
However you can still do

player.leaderstat.Points.Value += player.Values.toGive.Value * 2

BTW did you see my post because the first parameter is the player anyways so no need to pass the player name just used to automatically passed player parameter

1 Like