Hey guys, I can detect when a player just started a game and do some actions when a protective orb has gone,
local Players = game:GetService("Players")
for _, player in pairs(Players:GetPlayers()) do
-- this code will run for all players
Main_CHR_name = player.Name
break -- I got only one player for this epesode
end
Main_CHR = workspace:FindFirstChild(Main_CHR_name)
if RunService:IsStudio() == false then
-- games only
local the_orb = "xxx" -- what ever, but not nil
while the_orb ~= nil do
the_orb = Main_CHR:FindFirstChild("ForceField")
-- the_orb = Main_CHR:FindFirstChildOfClass("ForceField")
-- a line above is same thing
if not the_orb then
print("orb's gone")
break
else
print("waiting...")
wait(0.1)
end
end
end
The code works perfectly for those who just joined a game, but gives an error if a player has respawned. How to fix it?
In my game a player first get to a âlobbyâ, from which it can join a level of a game. But I do not want him to enter a level with the protective orb on. Somehow I have to detect it.
Unfortunately works in the same manner: only for the start and never for a respawn⌠same err⌠attempt to index nil with âFindFirstChildWhichIsAâ
The Orb is present though on the playerâŚ
I think thereâs a ForceField property called âDurationâ that you can set to â0â to completely remove the forcefield that spawns around you when you join. (Itâs in the SpawnLocation)
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
while task.wait() do
if character:FindFirstChild("ForceField") then
print(player.Name, " has a forcefield!")
--run code while they have forcefield
else
print(player.Name, " has lost their forcefield!")
--run code when the forcefield first ends
break --break out of loop if you dont need to check if player doesnt have forcefield
end
end
end)
end)
You donât need a script this complicated to achieve this.