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

This script only works in studio. The error states that ShopButton is not a member of player gui?

Asked by 5 years ago
for i,v in pairs(game:GetService("Players"):GetChildren()) do
    v.PlayerGui:WaitForChild("ShopButton").Frame:TweenPosition(UDim2.new(0.397,0,1.1,0))
end
0
is ShopButton a ScreenGui? SchonATL 15 — 5y
0
Is this a LocalScript or Sever Script? Server can’t edit PlayerGui. User#19524 175 — 5y
0
Also, you shouldn’t be using Players:GetChildren() but use Players:GetPlayers(). User#19524 175 — 5y
0
It's because your script is a server script and your game is Filtering Enabled. Use remove events and use :FireAllClients then tween the gui. INOOBE_YT 387 — 5y
0
thanks jakebball2014 84 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

That script of yours should work perfectly fine. It can only error if you have something other than a Player object residing in the Players service. Only Player objects should be there.

You used Instance:GetChildren() on the Players service, when you should be using Players:GetPlayers(). This exclusively returns players and only players.

If this is a LocalScript, this won’t work since you’re trying to edit the PlayerGui of another player. This is a thing to prevent exploiters from maliciously creating GuiObjects inside a player.

If this is a server Script, this wouldn’t work either, since the server can not access PlayerGui. So what can you do? Seems like what you want to accomplish won’t work...

Just kidding! I’ll use a RemoteEvent and it should work.

-- server Script under ServerScriptService

local remote = Instance.new"RemoteEvent"
remote.Name = "TweenAllGuis"
remote.Parent = game:GetService"ReplicatedStorage"

wait(.1) -- So the remote event has time to listen for OnClientEvent, else will error since the remote’s event wasn’t connected to a function.

for _, v in pairs(game:GetService("Players"):GetPlayers()) do
    remote:FireClient(v)
end

Now for the client code!

--LocalScript
local rep = game:GetService"ReplicatedStorage"
local plr = game:GetService("Players").LocalPlayer

rep:WaitForChild("TweenAllGuis").OnClientEvent:Connect(function()
    plr:WaitForChild("PlayerGui").ShopGui.Frame:TweenPosition(


    --TweenPosition code here. 

)

end)
Ad
Log in to vote
-1
Answered by 5 years ago

You don't use a WaitForChild for a GUI, add WaitForChild to .Frame

0
This should be a comment. User#19524 175 — 5y

Answer this question