"Unusual weapon" support

Original topic (with context): Cloning script cloning a bit too much

I had the bright idea to make the clones a kill brick, so you can use the friend as a weapon. When it spawns the clones, as it spawns them the exact same place as the real tool, it kills the player. I need to know how to make it so that it spawns the clones 5 studs away from the front of the player.

Current code:

local friend = script.Parent
local ball = friend.Handle
local db = false

if db == false then
	db = true
	script.Parent.Activated:Connect(function()
		local ballClone = ball:Clone()
		ballClone.Name = "Friend's Friend"
		ballClone.Parent = workspace
		ballClone.CanCollide = true
		ballClone.Position = ball.Position
		ballClone.Touched:Connect(function(hit)
			local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
			if hum then
				hum:TakeDamage(29453475935739457897057)
			end
		end)
		wait(10)
		ballClone:Destroy()
	end)
	
	wait(1)
	db = false
else
	db = false
	script.Parent.Activated:Connect(function()
		local ballClone = ball:Clone()
		ballClone.Name = "Friend's Friend"
		ballClone.Parent = workspace
		ballClone.CanCollide = true
		ballClone.Position = ball.Position
		ballClone.Touched:Connect(function(hit)
			local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
			if hum then
				hum:TakeDamage(29453475935739457897057)
			end
		end)
		wait(10)
		ballClone:Destroy()
	end)
	
	wait(1)
	db = true
end

Why do you have a debounce and an if statement that does effectively nothing in your case

As for spawning it 5 studs in front of the player

ballClone.CFrame = player.Character.PrimaryPart.CFrame + player.Character.PrimaryPart.CFrame.LookVector * 5

Add an offset to the position.

ballClone.CFrame = ball.CFrame * CFrame.new(Vector3.new(5,0,0))

That would spawn it 5 studs above the player

You could just change the the value of the x and z axis. I didn’t read the whole topic. Apologies.

That still doesn’t guarantee to spawn it in front of the player, he needs to use lookvector

Look in the other topic for the reason why there is a debounce and an if statement.

I copied your line of code into the place where the ballClone.Position code is and it didn’t work, nor did the part where is it meant to kill you.

It wouldn’t matter, try the script without it and you will get the exact same result.
Debounces are used when you have a loop and you dont want to run the same script twice or let it time to complete before running it again if its an event.
If the second option is what youre aiming for then youre doing it wrong

Right now your debounce and script are built in a way that it doesnt do anything;

You are setting the debounce to false
You check if its false and then set it to true
You connect the activated event
You set the debounce to false
and the debounce never runs again

If you want to wait for the function to finish before you run it again you need to put the debounce inside of the function.

It doesn’t guarantee it? What do you mean?

Still doesnt even work without the debounce and if.

Do you get any output? Or does it just spawn it somewhere else or breaks the script entirely

He asked to make it spawn in front of the player, not just at a 5 studs offset

1 Like

When I was still having trouble with the previous post, I had the function in a while true do loop. I then added the debounce because someone told me to, and then I figured out the problem (I think): adding an if statement. Absent mindedly, I kept and “fixed” the script so that it would still have the debounce without needing it in the if statement.

And I’ll check the output too now

Yeah, it would spawn the clone 5 studs in front of the player.

It wouldnt, it would spawn it in a 5 stud offset on the x axis, not always in the front (direction player is looking) of the player

Attempt to index “nil” with character. The classic.
Full error:
Players.DementedDivinity.Backpack.friend.Script:10: attempt to index nil with ‘Character’ - Server - Script:10

Well you didnt define the player, how would you spawn it in front of the player if you dont know who the player is?

script.Parent.Activated:Connect(function(player)