Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

If statement trouble == and ~= with Players?

Asked by 4 years ago

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)
0
Try using not (playerP == test) Sir_Ragealot 72 — 4y
0
I am using ~= techN0logics 40 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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 
0
Still doesn't work. techN0logics 40 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
Unlike @Sir_Ragealot answer the test value does not revive a name because it is already Boss.Name being sent to the player. techN0logics 40 — 4y

Answer this question