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

How to activate this script on touch and disabling it after a certain amount of time?

Asked by 3 years ago

I am having trouble making this script activate on touch and after a certain of amount time disable it. What is this script supposed to do? I am trying to activate this script on touch after the player has touched a certain part (thats not the model) the model will move and after a certain amount of seconds the script will be disabled and the model will stop moving. I tried breaking but I am not sure if I even used it correctly. help plz

script.Parent.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then

workspace.TWO.PrimaryPart = workspace.TWO.HumanoidRootPart

while true do
    for i = 1,100 do 
        wait()

                workspace.TWO:SetPrimaryPartCFrame(CFrame.new(workspace.TWO.PrimaryPart.Position + Vector3.new(0,0,1)))
                wait(4)
                break
              end
        end
    end
end)

0
well did it work when you broke it? sean_thecoolman 189 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

This should work:

local DB = false
script.Parent.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
        workspace.TWO.PrimaryPart = workspace.TWO.HumanoidRootPart
        if DB == false then
            DB = true 
            for i = 1,100 do 
                if i ~= 100 then --Checks to see whether or not i is equal to 100
                    workspace.TWO:SetPrimaryPartCFrame(CFrame.new(workspace.TWO.PrimaryPart.Position + Vector3.new(0,0,1)))
                    wait(4)
                else
                    script.Disabled = true --Disables the script if i is equal to 100
                end
           end
            else
        end
    end
end)

You should learn more about debounce, it's really useful in times like these.

Info about denounce: https://developer.roblox.com/en-us/articles/Debounce

Ad

Answer this question