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

Why is my anti Force Field script not functioning?

Asked by 10 years ago

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

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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.

Ad

Answer this question