Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Prioxis 673 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by
jav2612 180
10 years ago

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)
0
Thank you Prioxis 673 — 10y
Ad

Answer this question