Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question