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

Script not working like I want . Unachoring when somebody hits the block ?

Hello , I'm reposting this because I don't have any working awnsers :/

Hello , I thought that this script would have worked , welp it's working but like , I don't need to touch , if I wait , it will break :

function x(hit)
script.Parent.Anchored = false
script.Parent.GlassSound:Play()
script:remove()
end

script.Parent.Touched:connect(x)

I'm asking for your help , I want that when somebody hit the block , it's unanchoring . Thanks ;-;

1 comment

1

:remove() is deprecated, use Destroy instead.

1 answer

Problems in your code.

• Instance:remove() is deprecated, switch to Instance:Destroy()

• RBXScriptSignal:connect() is deprecated, switch to RBXScriptSignal:Connect()

When it comes to coding, it is important to not use deprecated code. It can break scripts, cause delay or lag, and just in general not work (from my experience).

Another thing is that the code will fire whenever ANYTHING touches it, so if it is on top of another part, (e.g. on top of the Baseplate if it’s on one) it counts as a touch. We must use the Instance:FindFirstChild(string name, bool recursive) method to check for a humanoid. If there is a humanoid, we have a player. Try this:

local function breakGlass(part)
    if part.Parent:FindFirstChild(“Humanoid”) then
        script.Parent.Anchored = false
        script.Parent.GlassBreak:Play()
        script:Destroy()
    end
end

script.Parent.Touched:Connect(breakGlass)

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