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)
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