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

Is it possible to put a time limit on a weapon??

Asked by 6 years ago

Hi there,

Is it possible to put a time limit on a weapon?? cant find it anywhere for the script for example picking up a weapon and only be able to use it for 15 seconds before it vanishes..

Hope it possible any help would be greatly appreciated..

Thanks

1
i mean you could use the delay function theking48989987 2147 — 6y

4 answers

Log in to vote
1
Answered by 6 years ago

As @theking48989987 mentioned you can use what is called a Delay Function, This function requires 2 arguments. First a time in seconds, After that you need to input a Function here's a few examples.

Here it is without an actual function. Which won't work and will give off an error.

delay(15, MyFunction)

Here it is with a included function that would work.

local function TimeLimit()
    print("Put your code in this function to remove it")
end

delay(3, TimeLimit)
0
Forgot to mention when doing the function you can always make it work for multiple weapons so whenever you want it to delay you can just call that function. But then you will have to make so that works with the actual function though. casper123123123 357 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Idk if this will help but, here's what you'd use to make it vanish

wait(15)
hit.Parent.Weapon:Destroy()
Log in to vote
0
Answered by 6 years ago

You can try something along the lines of

local f = *where the weapon is stored*:Clone
f.Parent = player.Backpack
wait(15)
f:Destroy()

This is presuming that you already have a way of detecting who picks up the weapon.

Log in to vote
0
Answered by 6 years ago

Thank you very much!!! kind of got it working...if it is ok to ask another question....

I have a spring aswell in the game which I got from the tool box I need to do the same thing otherwise people will just take advantage of it bouncing everywhere lol...How do I implement the same thing into the spring??

I have tried another script what you guys suggested but it fails to work any ideas??

sorry for the noob questions its probably easy!!...

here is the code..

Tool = script.Parent Handle = Tool:WaitForChild("Handle") CoilSound = Handle:WaitForChild("CoilSound")

EqualizingForce = (236 / 1.2) -- amount of force required to levitate a mass Gravity = 0.75 -- things float at > 1

GhostEffect = nil MassCon1 = nil MassCon2 = nil

function GetTotalMass(Parent) local TotalMass = 0 local function RecursiveGetMass(Parent) for i, v in pairs(Parent:GetChildren()) do if v:IsA("BasePart") and (v.Position - Character:GetModelCFrame().p).magnitude < 10 then if v.Name == "Handle" then TotalMass = (TotalMass + (v:GetMass() * EqualizingForce * 1)) else TotalMass = (TotalMass + (v:GetMass() * EqualizingForce * Gravity)) end end RecursiveGetMass(v) end end RecursiveGetMass(Parent) TotalMass = TotalMass * 1.125 return TotalMass end

function OnMassChanged(child, character) if GhostEffect and GhostEffect.Parent then GhostEffect.force = Vector3.new(0, GetTotalMass(Character), 0) end end

function UpdateGhostState(Unequipped) if Unequipped then GhostEffect:Destroy() GhostEffect = nil MassCon1:disconnect() MassCon2:disconnect() else if not GhostEffect then GhostEffect = Instance.new("BodyForce") GhostEffect.Name = "GravityCoilEffect" GhostEffect.force = Vector3.new(0, GetTotalMass(Character), 0) GhostEffect.Parent = Head MassCon1 = Character.ChildAdded:connect(function(Child) OnMassChanged(Child, Character) end) MassCon2 = Character.ChildRemoved:connect(function(Child) OnMassChanged(Child, Character) end) end end end

function OnEquipped() Character = Tool.Parent Head = Character:FindFirstChild("Head") if not Head or not Head.Parent then return end CoilSound:Play() UpdateGhostState(false) end

function OnUnequipped() UpdateGhostState(true) end

Tool.Equipped:connect(OnEquipped) Tool.Unequipped:connect(OnUnequipped)

Answer this question