Cloned tool not being parented to backpack

Final code could be -

local tool = script.Parent
local plr -- Wondering why I used a line which is not even defined ? Let's find it.
local ClonedTool = game.ReplicatedStorage.PaperAirplane:Clone()
tool.Bounce.OnServerEvent:Connect(function(player, event)

plr = player --Basically, we did a smart trick. We defined a variable plr which is nil. But if you don't know, we can easily assign player object to this variable and now the value of the variable is setted to player object. Now you can just call this variable as player!

	print(player)

local mouse = player:GetMouse()
	local ball = tool.Handle
	tool.Parent = workspace
	ball.CFrame = tool.Handle.CFrame
		ball.CFrame = CFrame.new(ball.Position, event)
		
		local BV = Instance.new("BodyVelocity", ball);
		BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		BV.Velocity = ball.CFrame.lookVector * 50 -- how fast it throws
		wait(.1)
		tool.Handle.BodyVelocity:Destroy()
end)

local isTouched=false

local Handle = script.Parent.Handle

script.Parent.Handle.Touched:Connect(function(hit)

	print("hit")

	if hit.Parent:FindFirstChild("Part") then
		print("Is part")
		wait(2)
		script.Parent:Destroy()

		local ClonedTool = game.ReplicatedStorage.PaperAirplane:Clone()

		ClonedTool.Parent = plr.Backpack

		print("Destroyed")
	end
end)
1 Like

Thanks! thanks for pointing out the errors aswell.

1 Like

NP, also I think people might have got confused on the plr part. So update is that I added notes for it so you can easily understand.

Sorry for bothering you, but do you know how to add Coins to the player once the airplane is destroyed?
ive already got a leaderstats script but Im having trouble giving coins.

It’s simple

local tool = script.Parent
local plr -- Wondering why I used a line which is not even defined ? Let's find it.
local ClonedTool = game.ReplicatedStorage.PaperAirplane:Clone()
tool.Bounce.OnServerEvent:Connect(function(player, event)

plr = player --Basically, we did a smart trick. We defined a variable plr which is nil. But if you don't know, we can easily assign player object to this variable and now the value of the variable is setted to player object. Now you can just call this variable as player!

	print(player)

local mouse = player:GetMouse()
	local ball = tool.Handle
	tool.Parent = workspace
	ball.CFrame = tool.Handle.CFrame
		ball.CFrame = CFrame.new(ball.Position, event)
		
		local BV = Instance.new("BodyVelocity", ball);
		BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		BV.Velocity = ball.CFrame.lookVector * 50 -- how fast it throws
		wait(.1)
		tool.Handle.BodyVelocity:Destroy()
end)

local isTouched=false

local Handle = script.Parent.Handle

script.Parent.Handle.Touched:Connect(function(hit)

	print("hit")

	if hit.Parent:FindFirstChild("Part") then
		print("Is part")
		wait(2)
		script.Parent:Destroy()

		local ClonedTool = game.ReplicatedStorage.PaperAirplane:Clone()

		ClonedTool.Parent = plr.Backpack

		print("Destroyed")

plr.leaderstats.Something.Value += value you want
	end
end)

Oop, thanks. I was overcomplicating it.

1 Like

Hey but the coin thing only works once for some reason, works fine when I play it solo?
Sorry, I just realized i didnt update the one in rs.

I actually doubted a bit on my code, I thought that this would happen, lemme recorrect my code.

Hi, could you check your messages please. I dont think i need to update this thread anymore

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.