Game not finding Value, even tho it gets found by :GetChildren()

I feel stupid asking this, cause i should know it, but somehow my game is finding “nil” instead of the value, which even gets listed. Is there something wrong with my “Arguments”?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:FindFirstChild("Events")
local VotingFolder = ReplicatedStorage:FindFirstChild("Voting")

local plrVoted = EventsFolder:FindFirstChild("PlayerVoted")

plrVoted.OnServerEvent:Connect(function(userId, Argument)
	if Argument == "Votes1" or "Votes2" or "Votes3" then
		print(Argument, userId)
		warn(VotingFolder:GetChildren())
		warn(VotingFolder:FindFirstChild(Argument)) --wont find me the argument
	else return
	end
end)
1 Like

if Argument == "Votes1" or "Votes2" or "Votes3" then is not a valid condition.
You must use Argument == for every single or
if Argument == "Votes1" or Argument == "Votes2" or Argument == "Votes3" then

1 Like

i used that, but while i used that, the argument did NOT go through that “filter”

yep, even tho i have a print after that if argument… my code wont go further (the code provided is all of the code). Thats quite weird

Is the Argument’s data type a string?

yes, the argument thats getting sent is completely the same as in the code i have provided; here is the one line which sends the event, to prove nothing should be wrong

plrVoted:FireServer(player.UserId, "Votes1")

Try looping through a folder and finding the instance this way.

I think problem here is in FindFirstChild(“”)
Use this instead

local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local VotingFolder = ReplicatedStorage:WaitForChild("Voting")
local plrVoted = EventsFolder:WaitForChild("PlayerVoted")

And this in warning:

warn(VotingFolder:WaitForChild(Argument))

Full script if you want:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local VotingFolder = ReplicatedStorage:WaitForChild("Voting")

local plrVoted = EventsFolder:WaitForChild("PlayerVoted")

plrVoted.OnServerEvent:Connect(function(userId, Argument)
	if Argument == "Votes1" or "Votes2" or "Votes3" then
		print(Argument, userId)
		warn(VotingFolder:GetChildren())
		warn(VotingFolder:WaitForChild(Argument)) --wont find me the argument
	else return
	end
end)

I think first parameter must be the player

3 Likes

The script is printing, which means that statement works and the problem is not in the parameters.

and that does not print the argument, instead its saying
image

Please implement these solutions:

(the first argument of OnServerEvent is always the player who fired it):

(that’s not how or works):

1 Like

i have accidentally misread that, sorry

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