Explanation [IMPORTANT]
- I did not make these scripts.
- I understand that there is a lot of excess code.
- I am predicting that they’re a lot of errors in these scripts.
The reason i’m bringing this to the Developer Forum is because my friend has been attempting to get this tool set-up for close to three years now. Once he gets this done, I can help him with the miniscule things.
Also, I am a novice when it comes to most of the Roblox Services and I am slowly but surely trying to learn how tools work.
Achieve
Okay so, what i’m attempting to do is help my friend get this Hockey Stick set-up.
Issues
There are two issues.
- When you are Idle and get passed the puck, it does not play an animation as it’s supposed to until you’ve moved and then go idle again.
- When the puck is stolen from a person, their animation does not change to the animation it’s supposed to change to.
- When you steal the puck, you would have the buck but the person you stole the puck from can still shoot the puck.
- When the puck is regenerated, the player breaks and has to reset to fix themselves.
- When you try to body check someone, you get stunned instead of the person you hit.
Photos
This is what the tool has inside of it.
Videos of Errors
Scripts
Just a note, all of these scripts are quite long due to excess code.
Animation Script
--[[Variables]]
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local runS = game:GetService("RunService")
local cas = game:GetService("ContextActionService")
local SprintDebounce = false
local tClc = 0
local char = player.Character
local humanoid = char.Humanoid
local idleTimer = -1
local idleTimer2 = -1
local hasPuck = script.Parent.HasPuck
local Speed = 0
char.Humanoid.WalkSpeed = 30
--[[Animations]]
local animation = Instance.new("Animation") -- normal skate
animation.AnimationId = "rbxassetid://2998126726"
local animTrack = humanoid:LoadAnimation(animation)
local animation2 = Instance.new("Animation") -- normal idle
animation2.AnimationId = "rbxassetid://2964890270"
local animTrack2 = humanoid:LoadAnimation(animation2)
local animation3 = Instance.new('Animation') -- idle with puck
animation3.AnimationId = 'rbxassetid://2969220681'
local animTrack3 = humanoid:LoadAnimation(animation3)
local animation4 = Instance.new('Animation') -- running with puck
animation4.AnimationId = 'rbxassetid://2969306036'
local animTrack4 = humanoid:LoadAnimation(animation4)
--[[Deactivation Function]]
function deActivation()
for _,anim in pairs(humanoid:GetPlayingAnimationTracks()) do
anim:Stop()
end
humanoid.WalkSpeed = 16
cas:UnbindAction("sprint")
game.Players.LocalPlayer.Character.Animate.Disabled = false
script.Disabled = true
end
--[[No Puck Function]]
local function NoPuck()
if humanoid.MoveDirection == Vector3.new(0,0,0) then
idleTimer2 = -1
if idleTimer == -1 then
animTrack3:Stop()
animTrack4:Stop()
animTrack2:Play()
idleTimer = 0
end
if idleTimer < 6 then
idleTimer = idleTimer + 0
end
if idleTimer >= 6 then
animTrack3:Stop()
animTrack4:Stop()
animTrack2:Play()
idleTimer = 0
end
animTrack:Stop()
else
idleTimer = -1
if idleTimer2 == -1 then
animTrack3:Stop()
animTrack4:Stop()
animTrack:Play()
idleTimer2 = 0
end
if idleTimer2 < 2 then
idleTimer2 = idleTimer2 + 2
end
if idleTimer2 >= 3 then
animTrack3:Stop()
animTrack4:Stop()
animTrack:Play()
idleTimer2 = 0
end
animTrack2:Stop()
end
end
--[[Puck Function]]
local function GotPuck()
if humanoid.MoveDirection == Vector3.new(0,0,0) then
idleTimer2 = -1
if idleTimer == -1 then
animTrack:Stop()
animTrack2:Stop()
animTrack3:Play()
idleTimer = 0
end
if idleTimer < 6 then
idleTimer = idleTimer + 0
end
if idleTimer >= 6 then
animTrack:Stop()
animTrack2:Stop()
animTrack3:Play()
idleTimer = 0
end
animTrack4:Stop()
else
idleTimer = -1
if idleTimer2 == -1 then
animTrack:Stop()
animTrack2:Stop()
animTrack4:Play()
idleTimer2 = 0
end
if idleTimer2 < 2 then
idleTimer2 = idleTimer2 + 2
end
if idleTimer2 >= 3 then
animTrack:Stop()
animTrack2:Stop()
animTrack4:Play()
idleTimer2 = 0
end
animTrack3:Stop()
end
end
humanoid.Running:Connect(function(speed)
Speed = speed
end)
local co = coroutine.wrap(function()
while wait(.2) do
if script.backward.Value == true then
local animTrack = humanoid:LoadAnimation(animation3)
end
if script.backward.Value == false then
local animTrack = humanoid:LoadAnimation(animation)
end
if hasPuck.Value then
GotPuck()
end
if not hasPuck.Value then
NoPuck()
end
script.Parent.Unequipped:Connect(deActivation)
end
end)
co()
--]]
local function actions(a, b, c)
if a == "sprint" and (b == Enum.UserInputState.Begin) then
tClc = tClc + 1
if SprintDebounce or (tClc < 2) then return end
local t = tick()
char.Humanoid.WalkSpeed = 34
SprintDebounce = true
repeat runS.Heartbeat:Wait() until tick() - t > 3.99
char.Humanoid.WalkSpeed = 30
tClc = 0
SprintDebounce = false
end
end
cas:BindAction("sprint", actions, false, Enum.KeyCode.R)
Puck Script
local player = game.Players.LocalPlayer
local puck = 'gamePuck'
local RunService = game:GetService("RunService")
local Cooldown = 1.5 --Seconds
local CooldownWait = nil
local region3 = require(workspace:WaitForChild("RotationR3"))
local Ocupada = false
local function weldBetween(a, b)
local weld = Instance.new("ManualWeld", a)
weld.Part0 = a
weld.Part1 = b
weld.Name = 'puckWeld'
weld.C0 = a.CFrame:inverse() * b.CFrame
return weld
end
local stick = script.Parent
local debounce = false
repeat RunService.Heartbeat:Wait() until script.Parent.Parent:FindFirstChild('Humanoid')
local char = script:FindFirstAncestorOfClass('Model')
local Human = char.Humanoid
local humanoid = Human
local HRP = char.Humanoid.Torso
local Puck = script.Parent.puckObject
local skate = script.Parent.skateaudio:Clone()
skate.Parent = char.Torso
local del = 3
local ch = false
local RunService = game:GetService("RunService")
humanoid.WalkSpeed = 30
stick.Equipped:connect(function()
Connection = RunService.Heartbeat:Connect(function()
-- if CooldownWait and tick() - CooldownWait < Cooldown then return end
local Puck = workspace:FindFirstChild("gamePuck") if not Puck then return end
if stick.HasPuck.Value or stick.Wait.Value then return end
if stick.isShooting.Value then return end
-- local Visual = Instance.new("Part")
-- game:GetService("Debris"):AddItem(Visual, .1)
-- Visual.CanCollide = false
-- Visual.Size = Radius.size
-- Visual.Anchored = true
-- Visual.CFrame = Radius.cframe
-- Visual.Parent = workspace
local Radius = region3.new(HRP.CFrame, Vector3.new(5.5, 6, 5.5)) -- SIZES X, Y, AND Z
local hit = Radius:castPoint(Puck.Position)
if hit then hit = Puck else return end
if not stick.HasPuck.Value then
CooldownWait = tick()
Ocupada = true
CooldownWait = tick()
-- debounce = true
-- delay(2,function()
-- debounce = false
-- end)
hit.hit:Play()
if not hit:FindFirstChild('puckWeld') then
hit.CFrame = HRP.CFrame * CFrame.new(.5,-2.8,-3.2) * CFrame.Angles((4*math.pi/2),0,0)
local W = Instance.new('WeldConstraint', hit) -- New Weld
W.Part0 = HRP
W.Part1 = hit
W.Name = 'puckWeld'
script.Parent.puckObject.Value = hit
stick.HasPuck.Value = true
else
local OStick = hit.puckWeld.Part0.Parent:FindFirstChild'Hockey'
hit.puckWeld:Destroy()
if OStick then
OStick.puckObject.Value = nil
OStick.HasPuck.Value = false
stick.isShooting.Value = false
end
end
end
if hit.Parent.Name == 'Hockey' and hit.Parent:IsA('Tool') then
local OtherStick = hit.Parent
stick.isShooting.Value = false
OtherStick.HasPuck.Value = false
pcall(function() OtherStick.puckObject.Value.puckWeld:Destroy() end)
OtherStick.puckObject.Value = nil
end
if not script.Parent.puckObject.Value and stick.HasPuck.Value then
stick.HasPuck.Value = false
stick.isShooting.Value = false
end
Ocupada = false
end)
end)
Human.Changed:connect(function()
if Human.Jump or Human.PlatformStand then
if script.Parent.puckObject.Value then
for i,v in pairs(script.Parent.puckObject.Value:GetChildren()) do
if v.Name == 'puckWeld' then
v:Destroy()
end
end
script.Parent.puckObject.Value = nil
end
if HRP:FindFirstChild("puckWeld") then
stick.possesion.Value = false
stick.isShooting.Value = false
for i,v in pairs(HRP:GetChildren()) do
if v.Name == 'puckWeld' then
v:remove()
end
end
end
end
end)
stick.Unequipped:connect(function()
Connection:Disconnect()
skate:Destroy()
script.Parent.puckObject.Value = nil
humanoid.JumpPower = 50
player.Character.Running.Volume = .6
script.Disabled = true
end)
script.RemoteEvent.OnServerEvent:Connect(function(player)
if not ch then
delay(3,function()
script.Parent.Handle.check:Play()
del = 80
ch = true
Human.WalkSpeed = 30
delay(0.4,function()
ch = false
Human.WalkSpeed = 25
end)
end)
end
end)
char['Right Arm'].Touched:connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") and otherPart.Parent ~= char and ch and not script.Parent.isShooting.Value and forceSpeed > 10 then
ch = false
debounce = true
delay(2,function()
debounce = false
end)
script.Parent.hitForce.MaxForce = Vector3.new(2000,0,2000)
local tempx = humanoid.MoveDirection.X
local tempz = humanoid.MoveDirection.Z
local newx = tempx*1*forceSpeed
local newz = tempz*1*forceSpeed
script.Parent.hitForce.Velocity = Vector3.new(newx,0,newz)
script.Parent.chestForce.MaxForce = Vector3.new(0,2000,0)
script.Parent.chestForce.Velocity = Vector3.new(0,50,0)
script.Parent.isChecking.Value = true
local player2 = game.Players:getPlayerFromCharacter(otherPart.Parent)
print(player2)
if player2 then
player2.PlayerValues.Ragdoll.Value = true
otherPart.Parent.Humanoid.PlatformStand = true
end
local hitsound = Instance.new('Sound')
hitsound.Parent = char['Right Arm']
hitsound.SoundId = "rbxassetid://367499850"
hitsound:Play()
local thrust = script.Parent.hitForce:Clone()
thrust.Parent = otherPart
wait(2*(forceSpeed/10))
script.Parent.isChecking.Value = false
local hurtsound = Instance.new('Sound')
hurtsound.Parent = player2.Character.Head
local random = math.random(1,5)
if random == 1 then
hurtsound.SoundId = "rbxassetid://132236747"
end
if random == 2 then
hurtsound.SoundId = "rbxassetid://132236764"
end
if random == 3 then
hurtsound.SoundId = "rbxassetid://132236768"
end
if random == 4 then
hurtsound.SoundId = "rbxassetid://132236780"
end
if random == 5 then
hurtsound.SoundId = "rbxassetid://141525175"
end
hurtsound:Play()
thrust:Destroy()
wait(1)
hurtsound:Destroy()
hitsound:Destroy()
player2.PlayerValues.Ragdoll.Value = false
otherPart.Parent.Humanoid.PlatformStand = false
otherPart.Parent.Humanoid.Jump = true
end
end)
Human.Running:connect(function(speed)
forceSpeed = speed
if forceSpeed > 2 then
skate.PlaybackSpeed = (forceSpeed / 12) + 1
skate.Volume = .25 + forceSpeed / 48
skate.Playing = true
end
if forceSpeed <= 2 then
skate.Playing = false
end
if del > 0 then
del = del - .5
end
if del < 0 then
del = del + .5
end
end)
Thank you for any help you can give me.