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

What's wrong with that ontouch script?

Asked by 8 years ago

Hello everyone, I have problem with ontouch script. It should make supply chest disapear, but don't work ;s Im beginner in scripting and tried to make "advanced script"... Later i'll try to add that chest will give player weapon from lighting, but first i want to make disapear.

Here is script:

local DebounceTime = 0.5

local Debounce = false
local Sup = script.Parent.Parent.Supply

local OnTouch = function(Part)
    local Humanoid = Part.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent)
        if Player then
            if not Debounce then
                Debounce = true
                for i = 1, 36 do
                    local Del = Sup:FindFirstChild("S"..i)
                    Del.Transparency = 1
                    Del.CanColide = false
                    end
                end

                wait(DebounceTime)

                Debounce = false
            end
        end
    end
script.Parent.Parent.Supply.Touched:connect(OnTouch)

Probably everything is wrong, but if someone can help.

0
Is there an error in the output? funyun 958 — 8y
0
Yeah error in output is in line 15. DevKarolus1 70 — 8y
0
But what does it say? funyun 958 — 8y
0
Make sure that there are 36 parts named S1, S2, S3, and so on. Make sure that those parts are direct children of "Supply". In general, make sure your hierarchy is correct. funyun 958 — 8y
0
Everything is correctly. DevKarolus1 70 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

try this

local DebounceTime = 0.5

local Debounce = false
local Sup = script.Parent.Parent.Supply

function OnTouch (Part)
    local Humanoid = Part.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent)
        if Player then
            if not Debounce then
                Debounce = true
                for i = 1, 36 do
                    local Del = Sup:FindFirstChild("S"..i)
                    Del.Transparency = 1
                    Del.CanColide = false
                    end
                end

                wait(DebounceTime)

                Debounce = false
            end
        end
    end
script.Parent.Parent.Supply.Touched:connect(OnTouch)
0
I don't know what you made here? It's same -.- DevKarolus1 70 — 8y
0
He changed Local OnTouched = function(part) with function OnTouch(part) as it is not needed and was never called minikitkat 687 — 8y
Ad
Log in to vote
0
Answered by
funyun 958 Moderation Voter
8 years ago
local DebounceTime = 0.5

local Debounce = false

--[[
    When accessing script.Parent.SomethingElse in the very beginning,
    it's best to use WaitForChild so you can be assured that you're only
    accessing it when it's loaded.

    script.Parent:WaitForChild("ClickDetector")
    script.Parent.Parent.Parent:WaitForChild("Frame")
    script.Parent.Parent:WaitForChild("Supply")
]]

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

local OnTouch = function(Part)  
    --Next line is a little more straightforward version of what you had.
    if game.Players:GetPlayerFromCharacter(Part.Parent) and not Debounce then
        Debounce = true

        --[[Method 1: GetChildren and pairs, for when you learn about tables.
        for _, child in pairs(Sup:GetChildren()) do
            if child:IsA("BasePart") or child:IsA("UnionOperation") then
                child.Transparency = 1
                child.CanCollide = false
            end
        end]]

        --Method 2: Your method. Still probably works if you have the hierarchy set up properly.

        for i = 1, 36 do
            local Del = Sup["S"..i]
            Del.Transparency = 1
            Del.CanCollide = true
        end

        wait(DebounceTime)
        Debounce = false
    end
end

Sup.Touched:connect(OnTouch)
0
0
I tried to make your method, but don't work ;/ DevKarolus1 70 — 8y
0
Everything is fine, but don't work ;/ DevKarolus1 70 — 8y

Answer this question