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

What's wrong with that ontouch script?

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.

5 comments

0

Is there an error in the output?

0

Yeah error in output is in line 15.

0

But what does it say?

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.

0

Everything is correctly.

2 answers

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)

2 comments

0

I don't know what you made here? It's same -.-

0

He changed Local OnTouched = function(part) with function OnTouch(part) as it is not needed and was never called

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)

3 comments

0
0

I tried to make your method, but don't work ;/

0

Everything is fine, but don't work ;/

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