local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
local PlayerTeam = PlayerService:FindFirstChild("TeamColor")
local PlayerGui = Player.PlayerGui
local Teams = game:GetService("Teams")
print("Player joined")
task.wait(1)
-- Modify items in player's local UI instance
local function checkGUI(Player)
local Player = PlayerService:FindFirstChildOfClass("Player")
local thisPlayerGui = Player:WaitForChild("PlayerGui") -- ensure the PlayerGui has loaded
local screenGui = thisPlayerGui.OtherSansGui
local team = PlayerTeam
team = BrickColor.new("Navy blue")
print("STAGE 1 COMPLETE")
if(Player == team) then
screenGui.Enabled = true
print("STAGE 2 COMPLETE")
elseif Player ~= team then
print("PLAYER IS NOT ON SANS TEAM")
end
end
--script:Destroy()
game.Players.PlayerAdded:Connect(checkGUI())
This is a LocalScript. There is a error saying this:
Attempt to connect failed: Passed value is not a function - Studio
Stack Begin - Studio
Script 'Players.borenreef.PlayerGui.OtherSansGui.TextButton.Frame.LocalScript', Line 26 - Studio - LocalScript:26
Stack End
and I do not know how to solve the error at all.
For context, I’m trying to make a GUI that appears for the “Sans” team player when they first join the game. Unforunately, I already ran into a error. Now, prints STAGE 1 COMPLETE and PLAYER IS NOT ON SANS TEAM do show up, but not the one in if(Player == team) then screenGui.Enabled = true print("STAGE 2 COMPLETE"), best seen with the error. I do not know what’s causing this or because of the lack of variables in the LocalScript and I’m not that experienced with LocalScripts compared to ServerScripts. Thus, I’m asking for help debugging. If anyone would respond, please do. I’d greatly appreciate getting the problem solved. Thank you!
Oh and for some of the script, some parts are not mine.
PlayerAdded is Connected as an Event after you join the game, so it wont fire when you join, but will when other players join.
LocalScripts require a Player to function, Events will be unaware of other events before it and wont fire for those unless explicitly told to.
So if this is needed on the Client whenever you join, you would either have the code run as soon as the LocalScript runs, or fire a RemoteEvent to your Client.
If you want a UI to only show for one team: I would recommend this:
local teamColor = BrickColor.new("Navy blue")
function UpdateUI()
local Player = game.Players["LocalPlayer"]
if Player.TeamColor==teamColor then
local PGUI = Player:WaitForChild("PlayerGui")
PGUI .OtherSansGui.Enabled = true
else
local PGUI = Player:WaitForChild("PlayerGui")
PGUI .OtherSansGui.Enabled = false
end
end
game.Players.LocalPlayer:GetPropertyChangedSignal("TeamColor"):Connect(UpdateUI)
Or if you wanna make it harder to exploit by using a regular script instead of a localscript:
local teamColor = BrickColor.new("Navy blue")
function UpdateUI(Player)
if Player.TeamColor==teamColor then
local PGUI = Player:WaitForChild("PlayerGui")
PGUI .OtherSansGui.Enabled = true
else
local PGUI = Player:WaitForChild("PlayerGui")
PGUI .OtherSansGui.Enabled = false
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player:GetPropertyChangedSignal("TeamColor"):Connect(UpdateUI)
end)
I tried the LocalScript version but added 2 print statements.
local teamColor = BrickColor.new("Navy blue")
function UpdateUI()
local Player = game.Players["LocalPlayer"]
if Player.TeamColor == teamColor then
local PGUI = Player:WaitForChild("PlayerGui")
PGUI.OtherSansGui.Enabled = true
print("APPEAR")
else
local PGUI = Player:WaitForChild("PlayerGui")
PGUI.OtherSansGui.Enabled = false
print("FALSE")
end
end
game.Players.LocalPlayer:GetPropertyChangedSignal("TeamColor"):Connect(UpdateUI)
When I ran the game, neither condition showed up. It doesn’t even look like it reached the if Player.TeamColor == teamColor then parts. Is there something wrong with the code?
I overlooked something, My fault. I forgot to make it run in the first place, so now it’s only running as you change the team. Let me fix that:
local teamColor = BrickColor.new("Navy blue")
function UpdateUI()
local Player = game.Players["LocalPlayer"]
if Player.TeamColor == teamColor then
local PGUI = Player:WaitForChild("PlayerGui")
PGUI.OtherSansGui.Enabled = true
else
local PGUI = Player:WaitForChild("PlayerGui")
PGUI.OtherSansGui.Enabled = false
end
end UpdateUI() --Added this here so it doesn't look messy in the rest of the script but still runs the function after its created for the first time.
game.Players.LocalPlayer:GetPropertyChangedSignal("TeamColor"):Connect(UpdateUI)