Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Finding player based on stringvalue not working? [SOLVED]

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

1 comment

0

solved it myself with the assistance of chess123mate. I had to send creatorName through the firing of the remote event

1 answer

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

3 comments

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

0

You could also store the creator in a InstanceValue

0

i mean ObjectValue

This discussion is preserved as it was. New answers, comments, and votes are closed.