(Friend solved it for me) I am making a script that detects when a player respawns, that toggles a BoolValue inside of a ScreenGUI, but for some reason it gives me an error when I try and locate it via script. Here is my code:

local Players = game:GetService("Players")
 
local function onCharacterAdded(character)
	local plr = game.Players:GetPlayerFromCharacter(character)
	plr.PlayerGui.HauntedSS.UsingScript.Value = false --here is where the error occurs
	print(plr.Name .. " has spawned")
end
 
local function onCharacterRemoving(character)
	local plr = game.Players:GetPlayerFromCharacter(character)
	plr.PlayerGui.HauntedSS.UsingScript.Value = false 
	print(plr.Name .. " is despawning")
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
	player.CharacterRemoving:Connect(onCharacterRemoving)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)

2 comments

1

Is this in a regular Script or LocalScript? And where is this script located?

0

It's a regular script in ServerScriptService, but it's fixed already, thanks though!