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

Why this ontouch script don't work?

Asked by 9 years ago

Hello everyone,I have problem with ontouch script. It should make supply chest disapear, but don't work ;s

Here is script:

local DebounceTime = 0.5

local Debounce = false
local Sup = script.Parent.Parent:WaitForChild("Supply")

local OnTouch = function(Part)
    if game.Players:GetPlayerFromCharacter(Part.Parent) and not Debounce then
        Debounce = true
        for _, child in pairs(Sup:GetChildren()) do
            if child:IsA("BasePart") or child:IsA("UnionOperation") then
                child.Transparency = 1
                child.CanCollide = false
            end

            end
            wait(DebounceTime)
        Debounce = false
        end
    end
script.Parent.Sup.Touched:connect(OnTouch)

I didn't saw any error output.

2 answers

Log in to vote
0
Answered by 9 years ago

The problem might be when you're calling the function. Since basically the script is reading line 20 as this:

script.Parent.script.Parent.Parent:WaitForChild("Supply")

Which doesn't look right does it? Maybe you should try getting rid of the Script.Parentbit in line 20, like this:

Sup.Touched:connect(OnTouch)

Hope this solved your problem! If you have anymore question then please feel free to post them down below!

EDITED:

local DebounceTime = 0.5

local Debounce = false
local Sup = script.Parent.Parent:WaitForChild("Supply")
local Model = script.Parent.Parent.Parent.SupplyChest
local OnTouch = function(Part)
    if game.Players:GetPlayerFromCharacter(Part.Parent) and not Debounce then
        Debounce = true
        for _, child in pairs(Model:GetChildren()) do
            if child:IsA("Part") or child:IsA("UnionOperation") then
                child.Transparency = 1
                child.CanCollide = false
            end

            end
            wait(DebounceTime)
        Debounce = false
        end
    end
Sup.Touched:connect(OnTouch)

-UserOnly16Characters

0
Still don't work. DevKarolus1 70 — 9y
0
You script seems like it should work fine but maybe the cause of the problem is the Parenting. Can you take a picture of the Hierarchy? UserOnly20Characters 890 — 9y
0
If you mean explorer screenshoot... https://gyazo.com/195d9bf937fef7bf5c3d2b3989ba38c2 DevKarolus1 70 — 9y
0
@DevKarolus1 Can you give us a better picture of your Hierarchy with the location of the script? UserOnly20Characters 890 — 9y
View all comments (6 more)
0
Ok i think this one will be good.. https://gyazo.com/08a4fc2b191389377d088c05178914bb DevKarolus1 70 — 9y
0
Do you want the script to activate when the Player touches the Part called Supply?!? UserOnly20Characters 890 — 9y
0
Yes. DevKarolus1 70 — 9y
0
Does it work now? UserOnly20Characters 890 — 9y
0
Thanks work perfectly ;) DevKarolus1 70 — 9y
0
No problem. As I suspected your parenting was a bit off etc. UserOnly20Characters 890 — 9y
Ad
Log in to vote
0
Answered by
DevArk 50
9 years ago

If the code I gave you does not work then check the tree of the Touched event

Like does the script's parent have a child called "Sup" or?

local DebounceTime = 0.5

local Debounce = false
local Sup = script.Parent.Parent:WaitForChild("Supply")

script.Parent.Sup.Touched:connect(function(prt)
    if game.Players:FindFirstChild(prt.Parent.Name) and Debounce == false then
        Debounce = true
        for _, child in pairs(Sup:GetChildren()) do 
            if child:IsA("BasePart") or child:IsA("UnionOperation") then
                child.Transparency = 1
                child.CanCollide = false
            end
        end
        wait(DebounceTime)
        Debounce = false
    end
end)

Answer this question