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 :

01local UIS = game:GetService("UserInputService")
02local player = game.Players.LocalPlayer
03local tool = script.Parent
04 
05repeat wait() until game.Players.LocalPlayer.Character
06char = game.Players.LocalPlayer.Character
07 
08local hum = char:FindFirstChild("Humanoid")
09 
10local Toss = hum:LoadAnimation(script.Parent.Animations.Toss)
11local Throw = hum:LoadAnimation(script.Parent.Animations.Throw)
12local TossPlaying = tool:WaitForChild("TossPlaying")
13 
14local mouse = player:GetMouse()
15local z = tool.Handle:Clone()
View all 69 lines...

A script named "SP" inside the throwscript

01script.Parent.Touched:Connect(function(hit)
02        local check = hit.Parent:FindFirstChildOfClass("Humanoid")
03                if check then
04                    local knock = Instance.new("BodyVelocity")
05                local hitsound = Instance.new("Sound", script.Parent)
06                hitsound:Play()
07                hitsound.SoundId = "rbxassetid://591409134"
08                hitsound.Volume = 1
09                    check:TakeDamage(100)
10                    knock.Parent = hit.Parent.Torso
11                    knock.maxForce = Vector3.new(math.huge,math.huge,math.huge)
12                    knock.velocity = script.Parent.CFrame.lookVector*135
13                    script.Parent.Anchored = true
14                    script.Parent.CanCollide = false
15                wait(5)
16            knock:Destroy()
17        script.Disabled = false
18    end
19end)

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."

01local MouseDownLast;
02InputBegan:connect(function(i)
03    if i.InputType == MouseButton1 then
04        MouseDownLast = tick()
05    end
06end)
07InputEnded:connect(function(i)
08    if i.InputType == MouseButton1 and (tick() - MouseDownLast) > 1 then
09        -- If it was held down for over a second
10    end
11end)

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