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

ThrowSystem Wont Work correctly?

Asked by 6 years ago
Edited 6 years ago

I made an throw script inside the rambo knife

there the throw script :

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local tool = script.Parent

repeat wait() until game.Players.LocalPlayer.Character
char = game.Players.LocalPlayer.Character

local hum = char:FindFirstChild("Humanoid")

local Toss = hum:LoadAnimation(script.Parent.Animations.Toss)
local Throw = hum:LoadAnimation(script.Parent.Animations.Throw)
local TossPlaying = tool:WaitForChild("TossPlaying")

local mouse = player:GetMouse()
local z = tool.Handle:Clone()
local SP = script.SP:Clone()

ready = false

UIS.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
    if ready == false then
            delay(1, function()
    Toss:Play()
    TossPlaying.Value = true
    ready = true
    end)
    end 
    end
end)

UIS.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
    if ready == true then
            script.Disabled = true
    Toss:Stop()
    Throw:Play()
    tool.Handle.Throw:Play()
    TossPlaying.Value = false
    local Projectile = z:Clone()
    local BV = Instance.new("BodyVelocity")
    local BAV = Instance.new("BodyAngularVelocity")
    local h = mouse.Hit

    Projectile.Parent = game.Workspace
    Projectile.CFrame = player.Character.Torso.CFrame*CFrame.new(math.random(-2,2),math.random(-1,1),-3)
    Projectile.CFrame = CFrame.new(Projectile.Position,mouse.hit.p)
    BV.Parent = Projectile

    BV.velocity = Projectile.CFrame.lookVector*135
    BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
    BAV.AngularVelocity = Vector3.new(15,15,15)
    BAV.MaxTorque = Vector3.new(4000,4000,4000)

    SP.Parent = Projectile
    SP.Disabled = false

    tool.Handle.Transparency = 1
    tool.Server.Disabled = true
    tool.Client.Disabled = true
    wait(5)
    tool.Handle.Transparency = 0
    tool.Server.Disabled = false
    tool.Client.Disabled = false
    ready = false
    script.Disabled = false
    end
end
end)

A script named "SP" inside the throwscript

script.Parent.Touched:Connect(function(hit)
        local check = hit.Parent:FindFirstChildOfClass("Humanoid")
                if check then
                    local knock = Instance.new("BodyVelocity")
                local hitsound = Instance.new("Sound", script.Parent)
                hitsound:Play()
                hitsound.SoundId = "rbxassetid://591409134"
                hitsound.Volume = 1
                    check:TakeDamage(100)
                    knock.Parent = hit.Parent.Torso
                    knock.maxForce = Vector3.new(math.huge,math.huge,math.huge)
                    knock.velocity = script.Parent.CFrame.lookVector*135
                    script.Parent.Anchored = true
                    script.Parent.CanCollide = false
                wait(5)
            knock:Destroy()
        script.Disabled = false
    end
end)

i want it work correctly

I need like when u hold the left mouse button it toss when up the button it throws, but mine works like: clicked = toss, click again = throw

1 answer

Log in to vote
0
Answered by 6 years ago

You need to either:

  • Remember when the mouse went down and check for the hold when it goes up
  • Keep a little state tracker. We're not going to do this.

Event magic

Normally you want to be checking everything when the mouse button is released. So, you need a little bit of stateless magic to say "Oh yeah, the mouse went down this long ago" rather than saying "I'll be ready in a second."

local MouseDownLast;
InputBegan:connect(function(i)
    if i.InputType == MouseButton1 then
        MouseDownLast = tick()
    end
end)
InputEnded:connect(function(i)
    if i.InputType == MouseButton1 and (tick() - MouseDownLast) > 1 then
        -- If it was held down for over a second
    end
end)

Obviously, you'll need to adjust this so that it works for you. tick is a Roblox builtin function that returns the current local time in seconds.

0
Everything works, but when i just click toss animation plays, but everything works, SunxLightz 30 — 6y
Ad

Answer this question