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

Gui Tweening script not working only on a server? [EDIT:ONE PART OF THE PROBLEM SOLVED]



script.Parent.Touched:Connect(function(HIT)
    local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
        local meep = game.Players.LocalPlayer.PlayerGui.ScreenGui.Shop
        meep:TweenPosition(UDim2.new(0.5,0,0.6,0),'In','Bounce',0.5)
end)

script.Parent.TouchEnded:Connect(function(HIT)
    local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
    local meep = game.Players.LocalPlayer.PlayerGui.ScreenGui.Shop
    meep:TweenPosition(UDim2.new(1.5,0,0.6,0),'Out','Bounce',0.5)
end)


This is a script to open a shop gui . It is in a normal script in a brick. It worked fine as well, until i added tweens. The tweens never worked in servers. The Gui just never shows up.

Can you please identify the problem and help me out?

EDIT: The first script's problem was solved. I accidentally uses Localplayer in a normal script XD.

1 answer

You're still using LocalPlayer...

On line 3 and line 9, instead of using the player variable, game.Players.LocalPlayer is trying to be accessed. Here is the fixed code.

script.Parent.Touched:Connect(function(HIT)
    local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
        local meep = player.PlayerGui.ScreenGui.Shop
        meep:TweenPosition(UDim2.new(0.5,0,0.6,0),'In','Bounce',0.5)
end)

script.Parent.TouchEnded:Connect(function(HIT)
    local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
    local meep = player.PlayerGui.ScreenGui.Shop
    meep:TweenPosition(UDim2.new(1.5,0,0.6,0),'Out','Bounce',0.5)
end)

Also, if your game has FE enabled (workspace.FilteringEnabled), then this will still throw an error, because GUIs inside a PlayerGui cannot be accessed from the server with FE on. You would have to setup a RemoteEvent.

local remote = Instance.new("RemoteEvent")
remote.Name = "TweenGui"
remote.Parent = workspace

script.Parent.Touched:Connect(function(HIT)
    local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
    remote:FireClient(player,true)
end)

script.Parent.TouchEnded:Connect(function(HIT)
    local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
    remote:FireClient(player,false)
end)

-- In LocalScript inside of ScreenGui.
script.Parent:WaitForChild("Shop")
workspace:WaitForChild("TweenGui").OnClientEvent:Connect(function(bool)
    if bool then
        script.Parent.Shop:TweenPosition(UDim2.new(0.5,0,0.6,0),'In','Bounce',0.5)
    else
        script.Parent.Shop:TweenPosition(UDim2.new(1.5,0,0.6,0),'Out','Bounce',0.5)
    end
end)

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