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

Player not being returned?

Once a players name is typed into "script.Parent.Parent.Player.Text" then it finds that user in Players. There are no errors so I tried putting prints in every line and it stops after local player = game.Players:FindFirstChild(user). It doesn't return/find the player I think. If it did then, it will change the players kills to whatever I enter in "Number".

function kills()
	if script.Parent.Parent.Player.Text == "" then
	else
		local user = script.Parent.Parent.Player.Text
		local player = game.Players:FindFirstChild(user)
		if player then
			player.playerstats.PlayerKill.Bandit.Value = script.Parent.Parent.Stats.Number
		end
	end
end
script.Parent.MouseButton1Click:connect(kills)

2 comments

0

Make sure your hierarchy is correct. Could you possibly take a picture and give it to us?

0

Are there any errors in the output? Try printing player.Name as well, see if anything comes up or if that ends up erroring out.

1 answer

✓ Accepted answer
function kills()
    if script.Parent.Parent.Player.Text == "" then
    else
        local user = script.Parent.Parent.Player
        for i,v in pairs(game.Players:GetChildren()) do
		if string.lower(v.Name) == string.lower(user.Text) then
			v.playerstats.PlayerKill.Bandit.Value = script.Parent.Parent.Stats.Number
		end
	end
    end
end
script.Parent.MouseButton1Click:connect(kills)

Here is a simplified and possibly working version. For line 4, I removed .Text because you can't have a variable with .Value in it, so it might be the same, did it to be safe.

Now what this script does is loops through all players. Using 'string.lower()' which turns all characters in a string to lowercase.

It changes the player's name to lowercase, along with user.Text and so you can type the player's name any way and it will still work.

If the player is found, then it will continue and set the player's "Bandit.Value".

Hope I helped! If not, I tried my best!

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