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

How To Make a GUI Show Up While In Contact with a Part?

Asked by 4 years ago

Essentially, while players are in contact with a certain uncancollided brick (its swamp water if you were curious), they are supposed to have a GUI show up on their screen to act as fog/swampgas. However, while in contact with the water, the GUI comes up but doesn't disappear when I leave the brick. Before adding a debounce (which I probably did incorrectly), the GUI would just glitch in and out as I walked through the brick (hence why I thought a debounce would fix it). Can anyone help me out with why this isn't working properly? Thanks so much in advance.

local Players = game:GetService("Players")
debounce = true

script.Parent.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum ~= nil and debounce == true then
        local player = Players:GetPlayerFromCharacter(hit.Parent)
        if player ~= nil then
            debounce = false
            player.PlayerGui.SwampGas.Enabled = true
            wait(1)
            debounce = true
        end
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum ~= nil then
         local player = Players:GetPlayerFromCharacter(hit.Parent)
         if player ~= nil then
             player.PlayerGui.SwampGas.Enabled = false
        end
    end
end)
0
Why is a server script handling GUIs? The server shouldn't be handling interface or input or be knowing about it. User#24403 69 — 4y
0
It's just a script inside of a brick that accesses the player gui of those who touch it. Is that so wrong? corncob567 275 — 4y
0
Use remote events and enable a GUI in the players PlayerGui cmgtotalyawesome 1418 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

A server sided script will not work with guis, It will fun the script correctly, However the client will not see anything due to it all being on the server. I have overcome this by adding a event or function that you can fire. You can use this event for multiple guis such as:

script.Parent.Touched:Connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    game.ReplicatedStorage.Functions.GuiHandler:InvokeClient(Player, "Gui1")
end

On the local end you could have something such as:

local Player = game.Players.LocalPlayer

for i, v in pairs(game.ReplicatedStorage.Functions) do
    if v:IsA("RemoteFunction") then
        local function Init(Player, ...)
            local Args = {...}

            if v.Name == "GuiHandler" then
                local GuiToHandle = Args[1]
                if Player.PlayerGui[GuiToHandle] then
                    Player.PlayerGui[GuiToHandle].Enabled = true
                    --You could index it to find more frames, And useTweenPosition. Ect..
                end
            end

        end

        v.OnClientInvoke = Init()
    end
end
0
But like, my script works. It just flashes when I move... corncob567 275 — 4y
Ad

Answer this question