so idk why is this happen but a instance from variable wont give me auto correect, i didnt do anything at all, i already tried reset all setting but nothing work can someone help me fix this issue?
here the video
with variable:
It would still work. It’s maybe because the players character hasn’t been created yet. Try using playerleave instead of player since you filtered it down to the local player only.
local player=game.Players.LocalPlayer
game.Players.PlayerRemoving:Connect(function(playerleave)
if playerleave.Character.Name==player.Character.Name then
--do your stuff--
end
end)
You could use any variable outside. This could be another option, but it could extend you code and could make more bugs. Remaking another variable doesn’t make sense.
If you want to define what things are going to be beforehand, you can always use the :.
For example in your case:
local player : Player = game.Players.LocalPlayer
Or for example, your receiving an event on your server and you want to specify that the second argument of this event is always going to be a boolean, you would do it like this
What are you trying to do here anyways? You don’t have to use PlayerAdded, since LocalScripts only start running when your client connects regardless. Also, your PlayerRemoving might not even fire, because your player left. You should handle stuff like this on the Server.
sorry im dumb at script, btw thank you! i never think about that before lol
btw i shoiuld just use like
local billboard = game.ReplicatedStorage.BillboardGui
player.CharacterAdded:Connect(function(character)
local billboardclone = billboard:Clone()
billboardclone.Parent = character:WaitForChild("Head")
end)
game.Players.PlayerRemoving:Connect(function(playerleave)
if player == playerleave then
end
end)
then it will work fine right now
i just need player instance, not the player name
You’re on the right track, but your logic is a bit off. I’ll correct your script.
This is a Script inside the ServerScriptService.
--//Variables//
local Players = game:GetService("Players") -- Get the Players Service
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Billboard = ReplicatedStorage.BillboardGui
--//Give the Player's character a billboard
Players.PlayerAdded:Connect(function(player) -- find the player that just connected
player.CharacterAdded:Connect(function(character) -- the player's character
local clone = Billboard:Clone()
clone.Parent = character:WaitForChild("Head")
end)
end)
--//Do something when a player leaves
Players.PlayerRemoving:Connect(function(player) -- "player" is the player that left
-- Do something with this player
end)