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

Finding player based on stringvalue not working? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

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.

01game.ReplicatedStorage.JoinRequestSend.OnServerEvent:Connect(function(player)
02    local guiButton = player.PlayerGui.FactionSelect.Main.PartiesList.Party.JoinParty
03    local creatorName = guiButton.Parent.PartyCreator.Value
04    local players = game:GetService("Players")
05    local creator = nil
06 
07    for i, player in pairs(players:GetPlayers()) do
08        if player.Name == creatorName then
09            creator = player
10        end
11    end
12 
13    local popup = game.ServerStorage.JoinReq:Clone()
14    popup.Parent = creator.PlayerGui
15end)

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...

0
solved it myself with the assistance of chess123mate. I had to send creatorName through the firing of the remote event proqrammed 285 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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:

1if creator then
2    --popup code here
3end
0
I'll try this out. I actually had the findfirstchild method before but since it wasn't working i tried the loop instead. ill put it abck to that and try ur idea proqrammed 285 — 5y
0
You could also store the creator in a InstanceValue Luka_Gaming07 534 — 5y
0
i mean ObjectValue Luka_Gaming07 534 — 5y
Ad

Answer this question