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)

2 comments
I changed this line of code but it still does not work. "game.ReplicatedStorage.PlayerName.OnServerEvent:Connect(getPlayerName)"
The FireServer() end of the RemoteEvent must be triggered from an event that passes a player. This includes PlayerAdded.