My variable wont give me

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 :slight_smile:
with variable:


.
.
without variable:

1 Like

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.

but when i using without variable its show the character instance

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 forgot to add character.

wait. my bad, its because i atempt using variable that outside from the if statement, i should make new variable

thx @Rintaro , i appreciate you answer

2 Likes

If Rintaro solved your problem then you should mark his reply as the solution. It’s forum etiquette.

2 Likes

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.

yes i feel weird too, its should be able to be used even if its outside from the if statement,

hmm alright, im sorry my bad. hehe

wait… i guess the issue not done yet, because what i ask is i can got a child from instance that i set on a variable

Must be a weird glitch with light theme, on dark theme it works 10/10 times (:

1 Like

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

Event.OnServerEvent:Connect(function(player : Player, thisIsABool : boolean)

end)

Specifying stuff likes this makes your coding life a bit easier.

is this can avoid NIL issue???! if yes thanks you so much!, i always got the useless nil value even if i didnt atempt to try that useless nil

not affect btw

honestly, just ignore it and use the playerleave variable. because of the if statement you know its the same player

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)

Your player == playerleave is unecessary.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.