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

Why isn't the ForceField destroying?

This script is inside of a TextButton. When you click the button you're supposed to lose 1000 points and have a ForceField around you for one second, then the ForceField Destroys.

The problem is after i lose my points and wait one second, the ForceField doesn't destroy.

script.Parent.MouseButton1Click:connect(function()
	if game.Players.LocalPlayer.Points.Value > 999 then
		local ff = game.Players.LocalPlayer.Character:FindFirstChild("ForceField")
		if not ff then
			local f = Instance.new("ForceField",game.Players.LocalPlayer.Character)
			game.Players.LocalPlayer.Points.Value = game.Players.LocalPlayer.Points.Value - 1000
			wait(1)
			print 'waited'
			if ff then
				print 'rip'
				ff:Destroy()
			end
		end
	end
end)

2 comments

0

line 9 (When fixed by the answer given) doesn't seem necessary unless somehow the ForceField will vanish in another way. You should just switch 9 out with "f:Destroy()" then where f:Destroy was before change

0

Well yeah but what if you reset?

1 answer

✓ Accepted answer

I think you made a typo

script.Parent.MouseButton1Click:connect(function()
    if game.Players.LocalPlayer.Points.Value > 999 then
        local ff = game.Players.LocalPlayer.Character:FindFirstChild("ForceField")
        if not ff then
            local f = Instance.new("ForceField",game.Players.LocalPlayer.Character)
            game.Players.LocalPlayer.Points.Value = game.Players.LocalPlayer.Points.Value - 1000
            wait(1)
            print 'waited'
	    --right here
            if f then
                print 'rip'
                f:Destroy()
            end
        end
    end
end)

1 comment

0

I did make a typo. Thanks!

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