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

playertowarn is not a vaild member of Players, please help!?

I'm making a warning system at the moment, and I need some help oof.

Here is the code:

local gmeplrs = game.Players
local playertowarn = script.Parent.Parent.Player.Text
local messagewarningtoplayer = script.Parent.Parent.WarningMessage.Text
local howdareyou = 1

script.Parent.MouseButton1Click:Connect(function()
    
gmeplrs.playertowarn.PlayerGui.Gui.Notifaction.Visible = true
gmeplrs.playertowarn.PlayerGui.Gui.Notification.Action.Text = messagewarningtoplayer
gmeplrs.playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "5"
wait(howdareyou)
gmeplrs.playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "4"
wait(howdareyou)
gmeplrs.playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "3"
wait(howdareyou)
gmeplrs.playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "2"
wait(howdareyou)
gmeplrs.playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "1"
wait(howdareyou)
gmeplrs.playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "0"
wait(howdareyou)
gmeplrs.playertowarn.PlayerGui.Gui.Notifcation.Visible = false
end)

In the output it says 'playertowarn is not a valid member of Players' **What do you think is wrong? **

1 answer

You're currently using a text value as an object, if you wanted to get the player then you would have to use gmeplrs:FindFirstChild(playertowarn)

I've fixed your script for you since it's short and simple.

local gmeplrs = game.Players
local howdareyou = 1

script.Parent.MouseButton1Click:Connect(function()

local playertowarn = gmeplrs:FindFirstChild(script.Parent.Parent.Player.Text) --update variables when event is fired
local messagewarningtoplayer = script.Parent.Parent.WarningMessage.Text

if playertowarn and messagewarningtoplayer then --makes sure variables aren't nil values

	playertowarn.PlayerGui.Gui.Notifaction.Visible = true --possible typo on your part?
	playertowarn.PlayerGui.Gui.Notification.Action.Text = messagewarningtoplayer
	playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "5"

	wait(howdareyou)

	playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "4"

	wait(howdareyou)
	
	playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "3"

	wait(howdareyou)

	playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "2"

	wait(howdareyou)

	playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "1"

	wait(howdareyou)

	playertowarn.PlayerGui.Gui.Notification.Countdown.Text = "0"

	wait(howdareyou)

	playertowarn.PlayerGui.Gui.Notifcation.Visible = false

	end

end)

I'd also recommend using camelcase for your variables and making your script easier to read.

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