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

Is this the right way to insert a forcefield into a player?

I'm at school right now so I won't be able to fully test my script til later but i'm trying to make a safezone styled script if someone hits a brick it'll insert a forcefield in their character and if you hit the other brick it'll take it out

function onTouched(hit)
local f = Instance.new("ForceField") -- is this the right way to insert it
f.Parent = hit.Parent -- is this the right way to put it in the players model
end
script.Parent.Touched:connect(onTouched)

this will be the script to insert the forcefield

function onTouched(hit)
local Player = hit.Parent:findFirstChild("ForceField")
if (Player ~= nil) then -- checks if player is there
hit.Parent.ForceField:remove() -- is this the correct way to remove the forcefield
end
script.Parent.Touched:connect(onTouched)

this will be the script that takes the forcefield out

is this the right way to find the forcefield and insert the forcefield into the player?

1 answer

✓ Accepted answer

the i in Instance should be capitalized, and you should check to make sure the forcefield exists before you try to remove it:

To insert:


function onTouched(hit)
	local f = Instance.new("ForceField") -- is this the right way to insert it
	f.Parent = hit.Parent -- is this the right way to put it in the players model
end
script.Parent.Touched:connect(onTouched)

To remove:

function onTouched(hit)
	ff = hit.Parent:FindFirstChild("ForceField")
	if ff ~= nil then	
		ff:Destroy() -- is this the correct way to remove the forcefield
	end
end
script.Parent.Touched:connect(onTouched)

1 comment

0

Thank you

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