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

Gift is not a valid member of PlayerGui ? - Help

Asked by 5 years ago

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.

0
you cant access GUI objects on the server User#23365 30 — 5y
0
so do that stuff on the client User#23365 30 — 5y
0
so would i use invokeserver TheOnlySmarts 233 — 5y
0
no.. User#23365 30 — 5y
View all comments (3 more)
0
use :FireServer() on a remote event User#23365 30 — 5y
0
RemoteFunctions are for RETURNING values User#23365 30 — 5y
0
Oh, but when I changed it to OnClientEvent it still didnt work. Could you answer the question as it'd be easier. Thanks! TheOnlySmarts 233 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)
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)? TheOnlySmarts 233 — 5y
0
Looking back it this, now helps me alot. Thanks! TheOnlySmarts 233 — 5y
Ad

Answer this question