UI won't go invisible for everyone

Hi, the UI that has a remotevent with it won’t go invisible. Here is my code:

local Player = game.Players.LocalPlayer
if not Player:WaitForChild("inMenu") then
	game.ReplicatedStorage.ToggleIntro.OnClientEvent:Connect(function(visibility)
		intro.Visible = visibility
		ShopBtn.Visible = visibility
		CoinUIBtn.Visible = visibility
		game.Workspace.Camera.CameraType = Enum.CameraType.Custom
		intro.Play.Text = "Play"			
	end)
end	

Normal script:

	game.ReplicatedStorage.ToggleIntro:FireAllClients(false)
1 Like

Your remote event seems to be set up correctly and I cannot spot any visible flaws with it.
Odds are that this issue is coming from the line if not Player:WaitForChild…. and players who do not meet that conditional value are not going to receive this event. I would suggest putting the if statement after the event is fired so that you check it every time like so:

game.ReplicatedStorage.ToggleIntro.OnClientEvent:Connect(function(visibility)
if not Player:WaitForChild("inMenu") then
		intro.Visible = visibility
		ShopBtn.Visible = visibility
		CoinUIBtn.Visible = visibility
		game.Workspace.Camera.CameraType = Enum.CameraType.Custom
		intro.Play.Text = "Play"			
	end
end)

Give that a try and if not let me know. Also are you getting any errors in your output?

hmm Still not working. i’ll remove that if statement

1 Like

That didn’t fix it. No errors too

in that case I would suggest print debugging the script on each line and seeing where it stops working

I would try:

game.ReplicatedStorage.ToggleIntro.OnClientEvent:Connect(function(visibility)
    if Player:FindFirstChild("inMenu") == nil then
		intro.Visible = visibility
		ShopBtn.Visible = visibility
		CoinUIBtn.Visible = visibility
		game.Workspace.Camera.CameraType = Enum.CameraType.Custom
		intro.Play.Text = "Play"			
	end
end)

Or honestly, instead of using :FireAllClients, you could loop through the players and check for “inMenu” like this:

for _, player in pairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("inMenu") == nil then
        game.ReplicatedStorage.ToggleIntro:FireClient(player, false)
    end
end

If “inMenu” is nil, then it does not exist or does not have any value

2 Likes

Along with that, you can do an else to keep its visibility at true:

for _, player in pairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("inMenu") == nil then
        game.ReplicatedStorage.ToggleIntro:FireClient(player, false)
    else
        game.ReplicatedStorage.ToggleIntro:FireClient(player, true)
    end
end

Then, in the local script:

game.ReplicatedStorage.ToggleIntro.OnClientEvent:Connect(function(visibility)
	intro.Visible = visibility
	ShopBtn.Visible = visibility
	CoinUIBtn.Visible = visibility
	game.Workspace.Camera.CameraType = Enum.CameraType.Custom
	intro.Play.Text = "Play"
end)
1 Like

Still not working… This is odd.

This line is poppng up blue in the output in the local script

Infinite yield hmm that’s an issue

Can you show me the hierarchy for the GUI?

I forgot to remove the if statement . It seemd to work now but I’m having teleporting issues for the “Beast”

Is the beast supposed to be 1 player?

Yes, the beast is dressed then teleported.

Alright, can you show me the part of the script where you choose the beast?

function module.ChoosePiggy(players)
	local RandomObj = Random.new()
	
	local chosenPiggy = players[RandomObj:NextInteger(1, #players)]
	
	return chosenPiggy
end

Ok so for the teleporting, I would do something like this:

for _, player in pairs(game.Players:GetPlayers()) do
    if player.Name ~= chosenPiggy then
        player.Character.HumanoidRootPart.CFrame = --player spawn CFrame
    else
        player.Character.HumanoidRootPart.CFrame = --beast spawn CFrame
    end
end

Where should I put this? 30 char

Wherever you teleport the players in your initial script is where that would go

make sure that it goes after your beast chooser function though

These are the functions for teleporting. I put that for loop in the middle?

function module.TeleportPiggy(player)
	if player.Character then
		player.Character.Humanoid.WalkSpeed = 14
		local bat = game.ServerStorage.Tools.PiggyBat:Clone()
		bat.Parent = player.Character
		
		if player.Character:FindFirstChild("HumanoidRootPart") then
			player.Character.HumanoidRootPart.CFrame = game.Workspace.WaitingRoom.PiggyWaitingSpawn.CFrame + Vector3.new(0,5,0)
		end
		
		local TrapCount = Instance.new("IntValue")
		TrapCount.Name = "TrapCount"
		TrapCount.Value = 5
		TrapCount.Parent = player
		
		game.ReplicatedStorage.ToggleTrap:FireClient(player, true)
		
	end
end

function module.TeleportPlayers(players, mapSpawns)
	for i, player in pairs(players) do
		if player.Character then
			local character = player.Character
			
			if character:FindFirstChild("HumanoidRootPart") then
				player.Character.Humanoid.WalkSpeed = 16
				
				local rand = Random.new()
				player.Character.HumanoidRootPart.CFrame = mapSpawns[rand:NextInteger(1, #mapSpawns)].CFrame + Vector3.new(0,10,0)
				
				local hitBoxClone = game.ServerStorage.Hitbox:Clone()
				hitBoxClone.CFrame = character.HumanoidRootPart.CFrame
				
				local weld = Instance.new("Weld")
				weld.Part1 = character.HumanoidRootPart
				weld.Part0 = hitBoxClone
				weld.Parent = character
				
				hitBoxClone.Parent = player.Character
			
			end
		end
	end
end