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

How to match up a players name with a string name?

I am new to i, v loops and am not sure how I would match up a string (a) to a players name?

game.ReplicatedStorage.Common.OnServerEvent:Connect(function(player, a)
	if player.leaderstats.Credits.Value >= 100 then
		player.leadersats.Credits.Value = player.leaderstats.Credits.Value - 100
		local plrs = game.Players:GetChildren()
		for i, v in pairs(plrs) do
			if a == plrs.Name then
			local a = -- That player
			end
		end
	end
end)

2 comments

0

What's the a variable supposed to be?

0

You don't really need a for loop. You can just do, if game.Players:FindFirstChild(a) then local newPlayer = a end

2 answers

Try this:

game.ReplicatedStorage.Common.OnServerEvent:Connect(function(originalplayer, a)
	local credits = originalplayer.leaderstats.Credits
	if credits.Value >= 100 then
        	credits.Value = credits.Value - 100
	end

	for i, player in pairs(game.Players:GetChildren()) do
		if a == player.Name then
			local a = player
		end
	end
end)

the answer might change depending on what "a" is

1 comment

0

bro

ummmm im not sure what ur asking but when u detect the remote event there's a parameter called player and thats the player and if ur wanting the name just do player.Name

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