You should learn about tools. They’re the easiest way of creating an item that can be used. You can perhaps use a tool to script a sword or a battle axe.
Oh hold on ya boy made a mistake, if you want different animations every click you can use a random function instead of relying on DBounce. I assumed DBounce was your click event- and in this case it should If you want what i said above here:
UserInputService.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 and not Dbounce then
DBounce = true
if Random:NextInteger(1,2) == 1 then
punch1Track:Play()
else if Random:NextInteger(1,2) == 2 then
punch2Track:Play()
end
wait(waitTIme)
DBounce = false
end
end)
Hha, its okay i make mistakes all the time! but im a bit confused on what NextInteger
does
Would i use random.new()
?
i tried running the code but it says Random is nil
edit- i just tried it with random.new and it worked!
Use math.random(1,2), here’s an example using part of your code.
mouse.Button1Down:Connect(function()
if DBounce == true then return end
DBounce = true
local random = math.random(1,2)
if random == 1 then
punch1Track:Play()
end
if random == 2 then
punch2Track:Play()
end
wait(5)
DBounce = false
end)
@rorystxr do this^ I totally screwed it up thanks @temporaryacount101
also you dont need to make random a variable it can be simplified down to
if math.random(1,2) == 1 then
punch1Track:Play()
else
punch2Track:Play()
end
I just have 1 more question.
So i was doing the damage part of the script, it worked but not in the way i expected.
Heres the code
Summary
if input.UserInputType == Enum.UserInputType.MouseButton1 and not DBounce then --Another way of saying "mouse.Button1Down"
DBounce = true
if random:NextInteger(1,2) == 1 then
punch1Track:Play()
humanoid.WalkSpeed = 0
RArm.Touched:Connect(function(hit)
if hit.Parent:WaitForChild("Humanoid") and hit:FindFirstAncestorWhichIsA("Model") then
local hitParent = hit.Parent
print(hitParent)
local humPart = hitParent:WaitForChild("HumanoidRootPart")
hitbox.Parent = humPart
hitbox.Position = humPart.Position
hitbox.Anchored = true
hitbox.Size = humPart.Size
hitbox.Transparency = 1
hitbox.Touched:Connect(function()
if not DBounce2 then
DBounce2 = true
print("ae")
hitParent.Humanoid:TakeDamage(18)
wait(waitTime)
DBounce = false
end
end)
end
end)
The error i got was Infinite yield possible on 'Workspace.R6.HumanoidRootPart:WaitForChild("Humanoid")'
Im not sure what i did wrong, help would be appreciated
The humanoid’s parent is not HumanoidRootPart that is what the error is. Go back to the line of the error and fix that part.
where would i find the line i need to fix? im still a bit confused
Does the output say a line or script name for the error?
Nope, it only says infinite yield. And i tried hitbox.Parent.Parent
(so basically the model, and the humanoid is parented to the dummy so im still confused)
Ohhh! i see i see, ill fix it and test it!
@Ripxff I tried it and it says that workspace doesnt have a humanoid. I used hit.Parent.Parent
go back to hit.Parent and do a print statement to see what hit actually is, cause doing .parent.parent gave you workspace lmao
if you need help you could just add
print(hit.Value)
Just a form of debugging
Ignore above, HumanoidRootPart is NOT under Humanoid, its a sibling under the Character. So it would be
hit:WaitForChild("HumanoidRootPart")
so i’d format is as if hit:WaitForChild("HumanoidRootPart") and hit:FindFirstAncestorWhichIsA("Model" then
@Ripxff im sorry for all the trouble
The output says Infinite yield possible on 'Workspace.R6.HumanoidRootPart:WaitForChild("HumanoidRootPart")'
And i edited the script with your advice. Im kinda lost on what to do now
You dont need that second part of the if statement anymore since we have the HumanoidRootPart alr
so i take out the model part? alright!!