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 4 years ago
Edited 4 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.

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

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

1 answer

Log in to vote
1
Answered by 4 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:

    if creator then
        --popup code here
    end
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 — 4y
0
You could also store the creator in a InstanceValue Luka_Gaming07 534 — 4y
0
i mean ObjectValue Luka_Gaming07 534 — 4y
Ad

Answer this question