Gui doesn't open when a player touches a part

Hey!
I’m trying to make a script that when a player touches a part, then gui opens for everyone, not just for the player that touched the part. (It would open for everyone so that everyone knows that this specific person touched the part)
I also wanted it to activate a kill script when the part is being touched.
Kill script does activate and the whole script works, except the gui part of it. The gui does not open. I’ve tried enabling the gui, then keeping gui enabled and tried making the frame visible instead, but none of these seem to work. I also don’t want to use LocalScript, since I want everyone to see the gui.

I’m pretty new to scripting, so any help would be appreciated!
I’ve looked for solutions in DevForum, but they just want the gui to appear for 1 person. I want the whole server to see it.
My current script:

script.Parent.Touched:Connect(function(hit)
     game.StarterGui.win.Enabled = true
     --then some kill script activation
     wait(5)
     game.StarterGui.win.Enabled = false
end)
2 Likes

That is because the Gui you are enabling isn’t inside the PlayerGui.

1 Like

You are using StarterGui, to open a GUI for a player you need to use PlayerGui.

2 Likes

One best thing you can do is use a remote event and FireAllClients() on it.

1 Like

Still doesn’t seem to work for some reason. The killing works but gui does not appear, even when it’s in PlayerGui and I make it enabled in PlayerGui.

1 Like

You could fire the client that touches the part and then the client can make it visible on a local script.

Try this

script.Parent.Touched:Connect(function(hit)
     for i,v in pairs(game.Players:GetPlayers()) 
           if v.PlayerGui then
               v.PlayerGui.win.Enabled = true
               wait(5)
               v.PlayerGui.win.Enabled = false
           end
     end
end)
1 Like

@Alvin_Blox got a video on this.

Try this :

 local debounce = false

    function getPlayer(humanoid) 
    	local players = game.Players:children() 
    	for i = 1, #players do 
    		if players[i].Character.Humanoid == humanoid then return players[i] end 
    	end 
    	return nil 
    end 

    function onTouch(part) 

    	local human = part.Parent:findFirstChild("Humanoid") 
    	if (human ~= nil) and debounce == false then
    		debounce = true

    		local player = getPlayer(human) 

    		if (player == nil) then return end 

    		script.Parent:clone().Parent = player.PlayerGui
    		wait(3)
    		debounce = false
    		player.PlayerGui.win:remove()
    		wait()
    		debounce = false
    		wait(5)
    	end
    end

script.Parent.Parent.Touched:connect(onTouch)

all you have to do is move your gui into part and add scripts to the gui

Thank you so much! It worked !

1 Like