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.
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)
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)