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

PlayerUI is not a valid member of PlayerGui?

Why is it now working this is my script PLS halp ME

local tool = script.Parent


local Settings = tool:WaitForChild("Settings")
local Strength = Settings.Strength

local Player = game.Players.localPlayer
local PlayerUI = Player:WaitForChild("PlayerGui").PlayerUI

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local CoinClicked = RemoteEvents.CoinClicked


local Debounce = false


tool.Activated:Connect(function()
    if Player.PlayerStats.CurrentValue.Value < Player.PlayerStats.Storage.Value then
        if Debounce == false then
            Debounce = true
            CoinClicked:FireServer(Strength.Value)
            wait(0.25)
            Debounce = false
        end
    else
        -- StorageFull Code
     end
 end)

2 comments

1

It is at StarterGui (this is the parent)

1

Your problem is probably one of two things, either the script is trying to access this "PlayerUI" object before its cloned to the player (In that case, do :WaitForChild("PlayerUI") OR you've put PlayerUI in the wrong place or something like that.

1 answer

I'm assuming that when the script is running, at line 8, it's checking for PlayerUI before it has existed at that time (By that I mean before the PlayerUI hasn't been cloned to PlayerGui at the moment the script was running). To fix this, just add another :WaitForChild for PlayerUI like this: local PlayerUI = Player:WaitForChild("PlayerGui"):WaitForChild("PlayerUI")

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