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

How do I make the forcefield instance invisible?

I have a brick that gives the player a permanent forcefield when they touch it, which works just fine. However, once I add the line of code to turn it invisible, that being forceField.Visible = false, the script no longer works. If I take the line out, it works again. This is the code I have:

local debounce = false 
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if h~=nil and debounce == false then
		debounce = true
		Field = Instance.new("ForceField")
		forceField.Visible = false
		Field.Parent = part.Parent
		wait(4)
		debounce = false
	end
end

if (script.Parent ~= nil) and (script.Parent.className == "Part") then 
	connection = script.Parent.Touched:connect(onTouched)
end

4 comments

0

Check output for errors, if there are none it's working or not running. Also use the code block format when posting code.

2

This is because forceField is not defined.

0

Why are you using parenthesis on line 14? Also, the property is called ClassName, not className, although I recommend using IsA() anyway. Next, you should be using FindFirstChild, not findFirstChild. On line 4, you can use "if not debounce then" to check if debounce is false. Finally, you should be using Connect, not connect. Please refrain from using deprecated code as it is a bad practice.

0

As INOOBE_YT said, forceField is not defined. You defined the ForceField as Field, so you should be using that variable to set its visibility. Replace line 7 with "Field.Visible = false".

1 answer

✓ Accepted answer

Hello, I'm blackorange and I will help!

#Problem:#

Your issue is force field isn't turning invisible

#Solution:#

Your solution is simply stick to 1 variable. Think: What do you want to call your forcefield?

In this case, you used Field. So a fix would be:

local debounce = false 
local function onTouched(part) -- Avoid global functions like global variables
    local h = part.Parent:FindFirstChild("Humanoid") -- :FindFirstChild is better
    if h~=nil and debounce == false then
        debounce = true
        Field = Instance.new("ForceField")
        Field.Visible = false -- this is ur issue
        Field.Parent = part.Parent
        wait(4)
        debounce = false
    end
end

if script.Parent ~= nil and script.Parent.className == "Part" then -- you don't need brackets
    connection = script.Parent.Touched:Connect(onTouched) -- :Connect not :connect
end

Hope this helped!

Best of luck developer!

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