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
Hello, I'm blackorange and I will help!
Your issue is force field isn't turning invisible
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!