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

How do I make the forcefield instance invisible?

Asked by 5 years ago
Edited 5 years ago

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

0
Check output for errors, if there are none it's working or not running. Also use the code block format when posting code. gullet 471 — 5y
2
This is because forceField is not defined. INOOBE_YT 387 — 5y
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. lunatic5 409 — 5y
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". lunatic5 409 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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!

Ad

Answer this question