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

Gift is not a valid member of PlayerGui ? - Help

I've been trying to work out and come across possible explanations for this issue but I can't seem to identify the error.

I get the error, "Gift is not a valid member of PlayerGui".

Here is my script it is erroring in. Line 5. The script is also in Workspace as it is a RemoteEvent script.

game.ReplicatedStorage.Events.Present.OnServerEvent:Connect(function()
	-- Any code will run when RemoteEvent is triggered/fired
	for i,v in pairs(game.Players:GetPlayers()) do
		v.leaderstats.Points.Value = v.leaderstats.Points.Value + 5000
		v.PlayerGui.Gift.cash.Visible = true
		v.PlayerGui.Gift.present.Visible = false
		game.Workspace.CoinSound:Play()
		v.leaderstats.gift.Value = true
		wait(0.2)
		v.PlayerGui.Gift.cash.TextSize = 40
		wait(0.2)
		v.PlayerGui.Gift.cash.TextSize = 48
		wait(2)
		v.PlayerGui.Gift.cash.Visible = false
		v.PlayerGui.Christmas.TextLabel.Visible = false
	end
end)

Anyone know any possible explanations to this error?

Here is also a screenshot of the PlayerGui and the Gui's inside of it.

https://i.gyazo.com/20540f5b045018ba14e6a05e7c910cbf.png

Thanks, TheOnlySmarts.

7 comments

0

you cant access GUI objects on the server

0

so do that stuff on the client

0

so would i use invokeserver

0

no..

0

use :FireServer() on a remote event

0

RemoteFunctions are for RETURNING values

0

Oh, but when I changed it to OnClientEvent it still didnt work. Could you answer the question as it'd be easier. Thanks!

1 answer

✓ Accepted answer

use RemoteEvents so the client can do it and you forgot to add the player parameter for OnServerEvent.

local remote = game.ReplicatedStorage.Events.Present

remote.OnServerEvent:Connect(function(player)
    -- Any code will run when RemoteEvent is triggered/fired

    for i,v in pairs(game.Players:GetPlayers()) do
        v.leaderstats.Points.Value = v.leaderstats.Points.Value + 5000  

        game.Workspace.CoinSound:Play()
        v.leaderstats.gift.Value = true

	remote:FireClient(player, "changeGui")      
    end
end)

client:

local remote = game.ReplicatedStorage.Events.Present
local holder = script.Parent.Parent -- define where they are

remote.OnClientEvent:Connect(function(changeGui)
	if changeGui == "changeGui" then

		holder.cash.Visible = true
		holder.present.Visible = false
	
		wait(0.2)
		holder.cash.TextSize = 40
		wait(0.2)
		holder.cash.TextSize = 48
		wait(2)
		holder.cash.Visible = false
		holder.Christmas.TextLabel.Visible = false
	end
end)

2 comments

0

Thank you this really helped but where would the second script be? What is the Client. I know the ServerScript would be in Workspace but what about the ClientScript(2nd script)?

0

Looking back it this, now helps me alot. Thanks!

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