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

Why is my anti Force Field script not functioning?

Script:

workspace.ChildAdded:connect(function(plyr)
local ff = plyr.ForceField
    if ff and ff.ClassName == "ForceField" then
	ff:remove()
end
end)

Output:

17:55:35.094 - ForceField is not a valid member of Model 17:55:35.094 - Script 'Workspace.Script', Line 2 17:55:35.095 - Stack End

Help:

The script knows the player(who is a model) exists, but not the Force Field. The Force Field does exist but It says the ForceField is not in the player even though It is!

1 answer

✓ Accepted answer

The problem with your script is that the event fired before the force field was created. Delaying the script a small amount of time should solve this.

Another problem, however, occurs when someone who isn't a player is added to workspace. This will cause your code to error because, although you check if ff exists, in the variable you are already assuming it exists! Use FindFirstChild().



But none of these fixes are necessary.

Every SpawnLocation has a Duration property that allows you to set the amount of time a player has a force field. Simply set it to 0 to get rid of it completely.

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