Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script not working? (ServerSided) ForceField Script Depending on team

Script inside server script service:

local Safe = game.Teams.Safe
local player = game.Players.LocalPlayer
local ForceField = Instance.new("ForceField")
if player.Team == Safe then
ForceField.Name = "NewForceField"
ForceField.Parent = player.Character
end

1 answer

You cannot access the LocalPlayer from the server, only on the client. Instead you would need to do something like this...

local Safe = game.Teams.Safe

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if player.Team == Safe then
			local forcefield = Instance.new("ForceField")
			forcefield.Name = "NewForceField"
			forcefield.Parent = character
		end
	end)
end

Alternatively this may not work due to the team being assigned when the character already exists, so you could also do something like this...

local Safe = game.Teams.Safe

game.Players.PlayerAdded:Connect(function(player)
	-- listen to when the player's team is changed
	player:GetPropertyChangedSignal("Team"):Connect(function()
		if player.Team == Safe then
			if player.Character then
				local forcefield = Instance.new("ForceField")
				forcefield.Name = "NewForceField"
				forcefield.Parent = player.Character
			end
		end
	end)
end

1 comment

0

Thanks ! The first script worked for me with a bit of editing, you forgot a parenthesis at the last end

This discussion is preserved as it was. New answers, comments, and votes are closed.