I thinks its only for a Local Script
PlayerAdded will not work. Any other solutions??
Okay here is something that I use sometimes. So I make a local script and then in that local script I make the Player Variable.
After that I fire a remote event and add the Player Variable within the event. Then go on from there to the Server Script
So like this?
local Remote = game.ReplicatedStorage.PlayerEvent
Remote:FireServer(game.Players.LocalPlayer)
game.ReplicatedStorage.PlayerEvent.OnServerEvent:Connect(function(Player)
--Then stuff here, but i would rather do a test to see if it works.
print(Player.Name)
print(Player.DisplayName)
Wait sorry I got mixed up with the context, just simply fire a remote event, no need to add anything in the parameters.
local Remote = game.ReplicatedStorage.PlayerEvent
Remote:FireServer(game.Players.LocalPlayer)
game.ReplicatedStorage.PlayerEvent.OnServerEvent:Connect(function(Player)
--Then stuff here, but i would rather do a test to see if it works.
print(Player.Name)
print(Player.DisplayName)
All you need to do is remove game.Players.LocalPlayer. I forgot that when you fire a remote event you are supposed to specify Player in the OnServerConnect line.
– This Is The Best Way
local plrs = game.Players
plrs.PlayerAdded:Connect(function(plr)
local tab = require(game.ServerScriptService.PlayerData)
local player = plrs[plr.name]
local playerStats = tab.GiveData(player)
local kills = playerStats[“Kills”]
local Humanoid = script.Parent.Humanoid
print(script.Parent.Parent.Name)
end)
that wont work and its not gonna find it!
for me the best way to get the player from server is player added, but you can also try to do a remote event from the client with player name info.