local EnergyBar = script.Parent
function getPlayerName(Plr)
return Plr.Name
end
game.ReplicatedStorage.PlayerName.OnServerEvent:Connect(getPlayerName())
EnergyBar.Activated:Connect(function()
print("test")
local player = getPlayerName()
print(player)
local character = game.Workspace[player]
player.Character.Humanoid.Health = player.Character.Humanoid.Health + 100
player.Character.Humanoid.WalkSpeed = 21
wait(30)
player.Character.Humanoid.WalkSpeed = 16
end)
Ah, it is a simple mistake with your argument. Because you didn't pass a parameter to the Plr
argument, the parameter to the argument is nil
. Just define it like this or some other way:
local function getPlayerName(Plr) return Plr.Name end game.Players.PlayerAdded:Connect(getPlayerName)
The above script will work because PlayerAdded
passes the player who joined the game as its parameter. This means that Plr
will have that parameter passed to it.