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