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

How do I make a temporary force field?

I want to make a game where you spawn in with a shield (So you don't get spawn killed), but when the timer gets down and you get tp'd into the game(A part, which you cannot see/touch, but it is really on a GrassPlate).

Script that puts you in the game:

local seconds = game.Workspace.Time
local ingame = game.Workspace.InGame.Value
local Game = game.Workspace.Game.Position


while true do

	wait(1)
	seconds.Value = seconds.Value - 1

	if seconds.Value == 0 and ingame == 0 then

		ingame = 1
		seconds.Value = 30

		local teleport = game.Players:GetChildren()
		for i = 1, #teleport do
			teleport[i].Character:MoveTo(Vector3.new(Game.X, Game.Y, Game.Z))

		end
	end

	if seconds.Value == 0 and ingame == 1 then

		ingame = 0
		seconds.Value = 15

		local teleport = game.Players:GetChildren()
		for i = 1, #teleport do
			teleport[i]:LoadCharacter()

		end
	end


end

I have a script in ServerScriptService that gives you a infinite Force Field:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local ff = Instance.new("ForceField")
		ff.Parent = character
	end)
end)

Here is the script in the GrassPlate that is supposed to make the Force Field go away:

script.Parent.Touched:Connect(function()
	game.Workspace.Parent.ServerScriptService.CoolScript.Disabled = true
end)

I have already got a few answers that do not answer my question. For instance, someone said that you can't disable the script, you have to destroy it. But that does not loop the script, so it did not work.

Thank you for your help!

1 answer

✓ Accepted answer
local a;script.Parent.Touched:Connect(function(v)
if a then return end;a=true
v=v.Parent;v=v and v:FindFirstChild"ForceField";v=v and v:Destroy()
wait(.4)
a=false
end)

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