How does click combat work?

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.

1 Like

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 :joy: 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)
2 Likes

Hha, its okay i make mistakes all the time! but im a bit confused on what NextInteger does :sweat_smile:

1 Like

Its a random function that returns an int between given parameters. Random

1 Like

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!

1 Like

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)
2 Likes

@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
2 Likes

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

1 Like

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.

3 Likes

where would i find the line i need to fix? im still a bit confused

1 Like

Does the output say a line or script name for the error?

1 Like

This line up here, you didn’t instantiate it properly like @Icey_CD said

3 Likes

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)

1 Like

Ohhh! i see i see, ill fix it and test it!

2 Likes

@Ripxff I tried it and it says that workspace doesnt have a humanoid. I used hit.Parent.Parent

1 Like

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 :grinning_face_with_smiling_eyes:

Ignore above, HumanoidRootPart is NOT under Humanoid, its a sibling under the Character. So it would be

hit:WaitForChild("HumanoidRootPart")
2 Likes

so i’d format is as if hit:WaitForChild("HumanoidRootPart") and hit:FindFirstAncestorWhichIsA("Model" then

2 Likes

@Ripxff im sorry for all the trouble :sweat_smile:

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 :sweat_smile:

1 Like

You dont need that second part of the if statement anymore since we have the HumanoidRootPart alr :grinning_face_with_smiling_eyes:

1 Like

so i take out the model part? alright!!

1 Like