Remote Functions Value Check?

Hi there, I’m pretty new to scripting,

So i’ve got this Remote Function that is supposed to check if a Value is == or not to the Player’s name however it always returns True?, Not sure if the cause is obvious or not i’m just unware what i’ve done wrong.

Local Script:

local booth = script.Parent
local click = game.Workspace.BoothBuy.ClickDetector
local boothOwners = game.Workspace.BoothOwners

click.MouseClick:Connect(function()
print(“You requested a Booth!”)
local isOwner = game.ReplicatedStorage.OwnerCheck:InvokeServer()
if isOwner == true then
print(“Yes”)
game.Players.LocalPlayer.PlayerGui.BoothEdit.Enabled = true
else
print(“No”)
end
end)

Script:

local booth = script.Parent
local click = game.Workspace.BoothBuy.ClickDetector
local boothOwners = game.Workspace.BoothOwners

game.ReplicatedStorage.OwnerCheck.OnServerInvoke = function(player)
print(“Reached Server”)
for i, v in pairs(boothOwners:GetChildren()) do
if v.Name ~= player.Name then
local newOwner = Instance.new(“IntValue”)
newOwner.Name = player.Name
newOwner.Parent = boothOwners
return true
else
return false
end
end
end

Thanks,

The server if-else logic doesn’t make sense. From what it looks like, the if statement returns true if the name of the child of boothOwners is NOT the name of the player. Thus, when it iterates through the children if just the first element in the array created by :GetChildren() is not the name of the player then it’ll return true everytime.

So, I would rewrite the logic to iterate through children and return true when v.Name==player.Name. Then, after iterating return false because that means no owner object was found.

Here’s what I’m trying to say:

for _,v in pairs (boothOwners:getChildren()) do
   if v.Name == player.Name then
      return true
   end
end

return false --  playerName was not found in boothOwners so we return false

Another problem I noticed was you create a newOwner object for the player if their name is not found. Basically you’re making EVERYONE an owner of the booth.

1 Like