So what I’m trying to do is limit a user from picking the same callsign as someone else in the game. I’m utilizing the same Remote Event for this.
The problem: Even if a player picked a callsign, it fails to give the requesting player the error message. It gives the requesting player the same callsign as the other user.
SERVER:
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new('Folder')
folder.Parent = player
folder.Name = "Callsigns"
local callsign = Instance.new('StringValue')
callsign.Parent = folder
callsign.Name = "Callsign"
end)
game.ReplicatedStorage.RadioCheck.OnServerEvent:Connect(function(player, callsign)
for _, plr in pairs(game:GetService("Players"):GetChildren()) do
if plr.Callsigns.Callsign.Value == callsign then
game.ReplicatedStorage.RadioCheck:FireClient(player, callsign, false)
print(plr.Name.." already has that callsign!")
else
game.ReplicatedStorage.RadioCheck:FireClient(player, callsign, true)
player.Callsigns.Callsign.Value = callsign
end
end
end)
CLIENT:
game.ReplicatedStorage.RadioCheck.OnClientEvent:Connect(function(callsign, status)
if status == true then
script.Parent.Parent.Main.UnitNumber.Value = callsign
script.Parent.Visible = false
elseif status == false then
script.Parent.Error.Visible = true
script.Parent.Error.Text.Text = "The callsign you picked is currently in use. Please pick another callsign."
end
end)
I don’t want other players to use the same callsign. For example, if player 1 has a callsign of “324”, I don’t want another player to be able to use 324.
Ohh, okay so you don’t already have code “Trying to do this”? cause i want to know if there’s a problem or you just haven’t made it yet and don’t know how to start
I would maybe use a table to store all of the call signs that have been sent and check if the callsign the player is trying to use is already in the table. If so the code does not continue
I currently have the code attached, and what the server is doing is its looping through all the players and checking if their callsign matches the one requested. If it does, it returns false (not allowed) and if not, true (allowed).
The problem is that its always returning true (player allowed to use callsign) even if the callsign is being used.