Hello!
So in my game I have a gui with parties that a player can click on to join, and then the party leader will have a gui pop up that asks if they either accept or decline the join request.
This is the code I have, that is fired from a remote even when the join button is clicked. It will put the pop up on the creator's screen.
game.ReplicatedStorage.JoinRequestSend.OnServerEvent:Connect(function(player) local guiButton = player.PlayerGui.FactionSelect.Main.PartiesList.Party.JoinParty local creatorName = guiButton.Parent.PartyCreator.Value local players = game:GetService("Players") local creator = nil for i, player in pairs(players:GetPlayers()) do if player.Name == creatorName then creator = player end end local popup = game.ServerStorage.JoinReq:Clone() popup.Parent = creator.PlayerGui end)
Even though the PartyCreator value is the correct name of the player, when I try to find the creator's player based on that value, it gives me this error and the gui does not pop up:
11:03:09.797 - ServerScriptService.JoinRequestSendReciever:13: attempt to index local 'creator' (a nil value)
Sorry, the answer is probably obvious... I will be extremely thankful if someone can help me figure out how to get this working...
I'd recommend printing out creatorName
- if it were the precise name of a player, the script would work fine.
You don't need that for loop, either, you can just use creator = players:FindFirstChild(creatorName)
, assuming you don't put anything into Players. Either way, you should make sure creator
exists before trying to use it:
if creator then --popup code here end