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

How do i put access PlayerGui through a LocalScript? (edit: the script type is a onclientevent)

It wont work, i always get an error

heres the script i put:

local rs = game:GetService("ReplicatedStorage")

rs:WaitForChild("PopUp").OnClientEvent:Connect(function(player, ptype, message)
	local playerGui = player.PlayerGui
	local gui = playerGui:WaitForChild("popUp")
	print(gui.Name)
	local displayText = gui:WaitForChild("_display")
	
	if ptype == "gain" then
		print(displayText)
		displayText.Text = message
		displayText.Visbile = true
		wait(.25)
		displayText.TextSize = 40
		wait(.25)
		displayText.TextSize = 35
		wait(.25)
		displayText.Visible = false
	end
end)

and it gives me this error:

Players.Actaully_Mine.PlayerGui.PopUpClient:5: attempt to index nil with 'WaitForChild'

help please!

3 comments

0

Line 4

0

So Wait, What Type Of Script Is This?

0

The problem is, your trying to index a nil property that doesnt exist make sure capilizations are correct

2 answers

Hello.


Unlike OnServerEvent, OnClientEvent does not have a "player" parameter, as you can just use LocalPlayer.


Here's your fixed script:

local rs = game:GetService("ReplicatedStorage")

local player = game.Players.LocalPlayer

rs:WaitForChild("PopUp").OnClientEvent:Connect(function(ptype, message)
    local playerGui = player.PlayerGui
    local gui = playerGui:WaitForChild("popUp")
    print(gui.Name)
    local displayText = gui:WaitForChild("_display")

    if ptype == "gain" then
        print(displayText)
        displayText.Text = message
        displayText.Visbile = true
        wait(.25)
        displayText.TextSize = 40
        wait(.25)
        displayText.TextSize = 35
        wait(.25)
        displayText.Visible = false
    end
end)

Hope this helps. Cheers!

1 comment

0

Didnt work :(

local rs = game:GetService("ReplicatedStorage")

rs:WaitForChild("PopUp").OnClientEvent:Connect(function(player, ptype, message)
    local playerGui = player:WaitForChild("PlayerGui")
    local gui = playerGui:WaitForChild("popUp")
    print(gui.Name)
    local displayText = gui:WaitForChild("_display")

    if ptype == "gain" then
        print(displayText)
        displayText.Text = message
        displayText.Visbile = true
        wait(.25)
        displayText.TextSize = 40
        wait(.25)
        displayText.TextSize = 35
        wait(.25)
        displayText.Visible = false
    end
end)

you should probably put waitforchild when trying to find anything in the player im not sure if there is a logical reason behind this beside it maybe not loading as fast as the script activates

1 comment

0

The point is i am firing it from server and i need to use player as a argument but it give me error

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