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

Gui Not appearing even when using .Visible = true.??

Asked by 5 years ago

Hey guys, so I have made this script so when you touch it a Gui appears, but it seems it doesn't work for some reason? please help.

local Buying = game.StarterGui.Buying.Frame

script.Parent.Touched:connect(function(otherPart)

Buying.Visible = true

end)

0
It's because your changing the startergui's visibility seith14 206 — 5y

2 answers

Log in to vote
-1
Answered by
seith14 206 Moderation Voter
5 years ago
Edited 5 years ago
local Players = game:GetService('Players') -- Getservice get's the Players from gameservice even if Players had a different name

script.Parent.Touched:connect(function(hit) -- when Touched
    if Players:FindFirstChild(hit.Parent.Name) then -- Finds hit.Parent.Name which should be the player
        local plr = Players:FindFirstChild(hit.Parent.Name) -- defines the player
        plr.PlayerGui.Buying.Visible = true -- Gets the PlayerGui from players and changes Buying to visible
    end
end)
0
Give some context and description. AdministratorReece 193 — 5y
0
It's simple, All he wants is the player's Buying to be visible not the startergui's visibility of the Buying seith14 206 — 5y
Ad
Log in to vote
2
Answered by 5 years ago

This is because you are using deprecated code, not using a remote event, and using StarterGUI when you use PlayerGUI. You can’t access the PlayerGui from the server and shouldn’t be.

--LocalScript under StarterGui/PlayerGui

local remote = Instance.new('RemoteEvent')
remote.Name = 'ShowGui'
remote.Parent = game:GetService'ReplicatedStorage'

local plr = game:GetService('Players').LocalPlayer
local pgui = plr:WaitForChild'PlayerGui'
local gui = game:GetService('ReplicatedStorage').Buying --put the gui in replicated

remote.OnClientEvent:Connect(function(enabled)
    if not pgui:FindFirstChild(gui.Name) then -- so we don’t overflow and lag our player
        gui:Clone().Parent = pgui --cloning our gui into Playergui, not startergui!!
        gui.Frame.Visible = enabled --set visibility 
    end
end)

.

-- Server script under the part

local plrs = game:GetService'Players'
local rep = game:GetService'ReplicatedStorage'

script.Parent.Touched:Connect(function(part) --connect is deprecated. use Connect
    local plr = plrs:GetPlayerFromCharacter(part.Parent) 

    if plr then
        rep.ShowGui:FireClient(plr, true) -- fire remote to client
    end
end) 

Answer this question