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.
01 | game.ReplicatedStorage.Events.Present.OnServerEvent:Connect( function () |
02 | -- Any code will run when RemoteEvent is triggered/fired |
03 | for i,v in pairs (game.Players:GetPlayers()) do |
04 | v.leaderstats.Points.Value = v.leaderstats.Points.Value + 5000 |
05 | v.PlayerGui.Gift.cash.Visible = true |
06 | v.PlayerGui.Gift.present.Visible = false |
07 | game.Workspace.CoinSound:Play() |
08 | v.leaderstats.gift.Value = true |
09 | wait( 0.2 ) |
10 | v.PlayerGui.Gift.cash.TextSize = 40 |
11 | wait( 0.2 ) |
12 | v.PlayerGui.Gift.cash.TextSize = 48 |
13 | wait( 2 ) |
14 | v.PlayerGui.Gift.cash.Visible = false |
15 | v.PlayerGui.Christmas.TextLabel.Visible = false |
16 | end |
17 | 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.
use RemoteEvents
so the client can do it and you forgot to add the player parameter for OnServerEvent
.
01 | local remote = game.ReplicatedStorage.Events.Present |
02 |
03 | remote.OnServerEvent:Connect( function (player) |
04 | -- Any code will run when RemoteEvent is triggered/fired |
05 |
06 | for i,v in pairs (game.Players:GetPlayers()) do |
07 | v.leaderstats.Points.Value = v.leaderstats.Points.Value + 5000 |
08 |
09 | game.Workspace.CoinSound:Play() |
10 | v.leaderstats.gift.Value = true |
11 |
12 | remote:FireClient(player, "changeGui" ) |
13 | end |
14 | end ) |
client:
01 | local remote = game.ReplicatedStorage.Events.Present |
02 | local holder = script.Parent.Parent -- define where they are |
03 |
04 | remote.OnClientEvent:Connect( function (changeGui) |
05 | if changeGui = = "changeGui" then |
06 |
07 | holder.cash.Visible = true |
08 | holder.present.Visible = false |
09 |
10 | wait( 0.2 ) |
11 | holder.cash.TextSize = 40 |
12 | wait( 0.2 ) |
13 | holder.cash.TextSize = 48 |
14 | wait( 2 ) |
15 | holder.cash.Visible = false |
16 | holder.Christmas.TextLabel.Visible = false |
17 | end |
18 | end ) |