Hello! I’ve been recently scripting a spectate menu. However, there is a small issue. In the player menu (players that can be spectated), the Frame that should get cloned for everybody only gets cloned to the targetplayer’s screen. (If their username is Player1, only Player1 will see the new Frame in the menu) Basically they can only see themselves and not other players.
It’s even more weird, as I specifically made a function for that, which should make it possible to get cloned to all players at the same time. As well as other functions, such as destroying for everyone, making something visible for everyone, etcetera.
The script:
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local DEBOUNCE = false
local SPECTATE_DEBOUNCE = false
for i, Player in pairs(Players:GetPlayers()) do
local Gui = Player.PlayerGui:WaitForChild("SpectateMenu")
local HolderFrame = Gui:WaitForChild("Holder")
local SpectateButton = HolderFrame:WaitForChild("SpectateButton")
local PlayerMenu = HolderFrame:WaitForChild("PlayerMenu")
local ScrollingFrame = PlayerMenu:WaitForChild("ScrollingFrame")
local Template = ScrollingFrame:WaitForChild("PlayerTemplate")
local Title = HolderFrame:WaitForChild("Title")
local function spectateButton()
if Player.Team == Teams.Dead or Player.Team == Teams.Spectators then
SpectateButton.Visible = true
elseif Player.Team == Teams.Alive then
SpectateButton.Visible = false
end
end
SpectateButton.MouseButton1Click:Connect(function()
if SPECTATE_DEBOUNCE == false then
PlayerMenu.Visible = true
Title.Visible = true
HolderFrame.Spectating.Visible = true
SPECTATE_DEBOUNCE = true
elseif SPECTATE_DEBOUNCE == true then
Title.Visible = false
HolderFrame.Spectating.Visible = false
PlayerMenu.Visible = false
SPECTATE_DEBOUNCE = false
end
end)
Player.CharacterAdded:Connect(spectateButton)
Player:GetPropertyChangedSignal("Team"):Connect(spectateButton)
Player:GetPropertyChangedSignal("Team"):Connect(function()
if Player.Team == Teams.Alive then
local Thumbnail = Players:GetUserThumbnailAsync(Player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size352x352)
local CloneTemplate = Template:Clone()
CloneTemplate.Parent = ScrollingFrame
CloneTemplate.Visible = true
CloneTemplate.Name = Player.Name
CloneTemplate.PlayerName.Text = Player.Name
CloneTemplate.PlayerThumbnail.Image = Thumbnail
CloneTemplate.PlayerName.MouseButton1Click:Connect(function()
if DEBOUNCE == false then
DEBOUNCE = true
local TargetPlayer = Players:FindFirstChild(tostring(CloneTemplate.Name))
print("TargetPlayer: "..TargetPlayer.Name)
HolderFrame.Spectating.Text = "SPECTATING: "..TargetPlayer.Name
local Camera = workspace.CurrentCamera
Camera.CameraSubject = TargetPlayer.Character:WaitForChild("Head")
elseif DEBOUNCE == true then
local Camera = workspace.CurrentCamera
Camera.CameraSubject = Player.Character:WaitForChild("Head")
HolderFrame.Spectating.Text = "SPECTATING: N/A"
DEBOUNCE = false
end
end)
elseif Player.Team == Teams.Dead or Teams.Spectators then
local TargetTemplate = Player.PlayerGui:WaitForChild("SpectateMenu"):WaitForChild("Holder"):WaitForChild("PlayerMenu"):WaitForChild("ScrollingFrame"):FindFirstChild(tostring(Player.Name))
print("before if check")
if HolderFrame.Spectating.Text == "SPECTATING: "..Player.Name then
print("after if check")
print("before destroy on if")
TargetTemplate:Destroy()
print("after destroy on if")
HolderFrame.Spectating.Text = "SPECTATING: N/A"
local Camera = workspace.CurrentCamera
Camera.CameraSubject = Player.Character:WaitForChild("Head")
else
TargetTemplate:Destroy()
end
end
end)
end