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

How can I make an object, when touched, move 15 studs down for a period of 90s?

Asked by 6 years ago

How can I make a part, when touched by a player, be move 15 studs down (vertically) for a period of 90 seconds then move back to where it began? I want the part to remain at its default location **until **it is touched by a player.

The brick intended to be the parent of the script is actually a sword-giver in my game. But rather than the giver being capable of delivering infinite swords, I want to regulate the rarity of the particular sword attached to it.

Here is the link to my free model that is the sword giver: https://www.roblox.com/library/1315180241/Sword-Giver


If you can think of a simpler way of accomplishing the same thing, please let me hear it! I appreciate all the help I get!

Also, please feel free to visit this game that I have put so much effort in over the years! I love to receive good criticism and new ideas! https://www.roblox.com/games/100869388/Sword-Fighting-Celestial-Concept#!/about

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

Use the tween service.

local brick = script.Parent -- define this
local start = brick.CFrame
local goal = brick.CFrame * CFrame.new(0,-15,0)
local TweenService = game:GetService("TweenService")
local debounce = false

brick.Touched:Connect(function(hit)
    local player = false
    for i,v in pairs(game.Players:GetPlayers())do
        if v and v.Character and hit:IsDescendantOf(v.Character)then
            player = true
        end
    end
    if not player then return end
    if debounce then return end
    debounce = true
    local tween = TweenService:Create(brick,TweenInfo.new(90,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,true),{CFrame = goal})
    tween:Play()
    tween.Completed:Wait()
    debounce = false
end)

This will cause the whole durstion to be 90 seconds. If you want it to be so that it goes down for 90 seconds, then up for another 90, change the 90 on line 17 to 180

0
This works great! But instead of the part taking 90 seconds to move: I need it to move the given distance (only moving after being touched), stay there for 90 seconds, then move back to the default location (reappearing) Hiremetobuildforyou 6 — 6y
0
Staying at the changed location is the missing part Hiremetobuildforyou 6 — 6y
0
Figured it out! Thank you Hiremetobuildforyou 6 — 6y
Ad

Answer this question