Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

If statement trouble == and ~= with Players?

For some reason, if the test and playerP are == to each other it will run. In testing both the test and playerP will equal the player's name.

local PLAYERS = game:GetService("Players")

local playerP = PLAYERS.LocalPlayer

game.ReplicatedStorage.RemoveNPC.OnClientEvent:Connect(function(test)
print("Fired")
print(test)
print(playerP)
if playerP ~= test then
	print("B")
	local way = game.Workspace:WaitForChild("wayFind")
	way:Destroy()
	print("E")
end
end)

2 comments

0

Try using not (playerP == test)

0

I am using ~=

2 answers

So I think the problem with the code is the fact that you are getting 2 different player Instances. The if statement compares the instance PlayerP to the instance Test, but one is on the client and one is on the server. In order to fix this issue, I would compare the names of the player(s) like so:

if playerP.Name ~= test.Name then 

1 comment

0

Still doesn't work.

Okay, I found out why what happened. My playerP value needs a .Name because of the test value being sent to the player is Boss.Name.

local PLAYERS = game:GetService("Players")

local playerP = PLAYERS.LocalPlayer

game.ReplicatedStorage.RemoveNPC.OnClientEvent:Connect(function(test)
print("Fired")
print(test)
print(playerP.Name)
if playerP.Name ~= test then --THIS LINE HERE
	print("B")
	local way = game.Workspace:WaitForChild("wayFind")
	way:Destroy()
	print("E")
end
end)

1 comment

0

Unlike @Sir_Ragealot answer the test value does not revive a name because it is already Boss.Name being sent to the player.

This discussion is preserved as it was. New answers, comments, and votes are closed.