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

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

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)

3 comments

0

Why is a server script handling GUIs? The server shouldn't be handling interface or input or be knowing about it.

0

It's just a script inside of a brick that accesses the player gui of those who touch it. Is that so wrong?

0

Use remote events and enable a GUI in the players PlayerGui

1 answer

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

1 comment

0

But like, my script works. It just flashes when I move...

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