Tool.CoinScript.Disabled=false function onEquipped()dBody=Instance.new("\080\097\114\116")dBody.Parent=game.Workspace dBody.Name="\068\114\101\105\100\101\108\066\111\100\121"dBody.BrickColor=BrickColor.Red()dBody.Size=Vector3.new(2.56,2.56,2.56)dBody.Shape=1 dBody.BackSurface="\083\109\111\111\116\104"dBody.BottomSurface="\073\110\108\101\116"dBody.FrontSurface="\083\116\117\100\115"dBody.TopSurface="\083\109\111\111\116\104"dBody.LeftSurface="\083\109\111\111\116\104"dBody.RightSurface="\083\109\111\111\116\104";(Tool.Handle.Mesh:Clone()).Parent=dBody dreidlesound=Instance.new("\083\111\117\110\100")dreidlesound.SoundId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\049\057\048\055\051\055\051\054"dreidlesound.Parent=dBody coinsound=Instance.new("\083\111\117\110\100")coinsound.SoundId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\049\057\048\055\051\049\055\054"coinsound.Parent=dBody dBase=Instance.new("\080\097\114\116")dBase.Parent=game.Workspace dBase.Name="\068\114\101\105\100\101\108\066\097\115\101"dBase.BrickColor=BrickColor.Black()dBase.Size=Vector3.new(2,2,2)dBase.Shape=0 dBase.Transparency=1 dBase.BottomSurface="\083\109\111\111\116\104"w2=Instance.new("\087\101\108\100")w2.Name="\068\114\101\105\100\101\108\087\101\108\100"w2.Part0=dBody w2.Part1=dBase w2.C0=CFrame.new(0,0,0)w2.C1=CFrame.new(0,1.75,0)w2.Parent=script.Parent.Handle end Tool.Enabled=true function onActivated(a)Tool.Handle.Transparency=1 if not Tool.Enabled then return end Tool.Enabled=false local Q=Tool.Parent local d=Q.Humanoid if d==nil then print("\072\117\109\097\110\111\105\100 \110\111\116 \102\111\117\110\100")return end local B=d.TargetPoint local c=game.Players:playerFromCharacter(Q)head=Q:findFirstChild("\072\101\097\100")if head==nil then print("\072\117\109\097\110\111\105\100 \110\111\116 \102\111\117\110\100")return end dist=(head.Position-B).magnitude if dist>30 then Tool.Enabled=true Tool.Handle.Transparency=0 return end dreidlesound:Play()dBody.CFrame=(CFrame.fromEulerAnglesXYZ(0,0,0)+B)+Vector3.new(0,2.5,0)dBody.RotVelocity=Vector3.new(math.random(0,7),math.random(20,80),math.random(7,9))wait(2.8)frontVector=dBody.CFrame:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Front))leftVector=dBody.CFrame:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Left))test1=frontVector.y test2=leftVector.y if math.abs(test1)>math.abs(test2)then if test1>0 then count=0 else count=5 end else if test2>0 then count=15 else count=25 end end coinsound:Play()for a=1,count,1 do local Q=Instance.new("\080\097\114\116")Q.BrickColor=BrickColor.new(23)Q.formFactor=2 Q.Size=Vector3.new(1,.2,1)Q.TopSurface=0 Q.BottomSurface=0 local d=math.random()*6.28 local B=(Vector3.new(math.cos(d),0,math.sin(d))).unit Q.Velocity=B*25 Q.RotVelocity=B Q.Position=((dBody.Position+Vector3.new(0,2,0))+Vector3.new(0,math.random()*3,0))+B*2 Q.Parent=game.Workspace;(Tool.Mesh:Clone()).Parent=Q;(Tool.CoinScript:Clone()).Parent=Q debris:AddItem(Q,60)end Tool.Enabled=true Tool.Handle.Transparency=0 end
--local Pellet = Tool.Handle:Clone() --Tool.Handle:Clone()
--Tool.CoinScript:Clone().Parent = Pellet
Tool.CoinScript.Disabled = false

function onEquipped()
	--body of the dreidel
	dBody = Instance.new("Part")
	dBody.Parent = game.Workspace
	dBody.Name = "DreidelBody"
	dBody.BrickColor = BrickColor.Red()
	dBody.Size = Vector3.new(2.56, 2.56, 2.56)
	dBody.Shape = 1
	dBody.BackSurface = "Smooth" --used this of debugging to test which side was face up
	dBody.BottomSurface = "Inlet"
	dBody.FrontSurface = "Studs"
	dBody.TopSurface = "Smooth"
	dBody.LeftSurface = "Smooth"
	dBody.RightSurface = "Smooth"
	Tool.Handle.Mesh:Clone().Parent = dBody --sets the dreidel mesh to the cube part of the dreidel

	--Dreidle Sound
	dreidlesound = Instance.new("Sound")
	dreidlesound.SoundId = "http://www.roblox.com/asset/?id=19073736" -- replace me
	dreidlesound.Parent = dBody

	--Coin Sound
	coinsound = Instance.new("Sound")
	coinsound.SoundId = "http://www.roblox.com/asset/?id=19073176" --replace me
	coinsound.Parent = dBody

	--base of the dreidel
	dBase = Instance.new("Part")
	dBase.Parent = game.Workspace
	dBase.Name = "DreidelBase"
	dBase.BrickColor = BrickColor.Black()
	dBase.Size = Vector3.new(2, 2, 2)
	dBase.Shape = 0
	dBase.Transparency = 1
	dBase.BottomSurface = "Smooth"

	--welding the body fo the dredeil to the base
	w2 = Instance.new("Weld")
	w2.Name = "DreidelWeld"
	w2.Part0 = dBody
	w2.Part1 = dBase
	w2.C0 = CFrame.new(0, 0, 0)
	w2.C1 = CFrame.new(0, 1.75, 0)
	w2.Parent = script.Parent.Handle
end

Tool.Enabled = true
function onActivated(mouse_pos)
	Tool.Handle.Transparency = 1
	if not Tool.Enabled then
		return
	end

	Tool.Enabled = false

	local character = Tool.Parent
	local humanoid = character.Humanoid
	if humanoid == nil then
		print("Humanoid not found")
		return
	end

	--locates the position the mouse is targeting
	local targetPos = humanoid.TargetPoint

	local vPlayer = game.Players:playerFromCharacter(character)
	head = character:findFirstChild("Head")
	if head == nil then
		print("Humanoid not found")
		return
	end

	--calculates the distance between the person and the possible dreidle location
	dist = (head.Position - targetPos).magnitude

	--prevents the dreidle for being created too far away from the player
	if dist > 30 then
		Tool.Enabled = true
		Tool.Handle.Transparency = 0
		return
	end

	--PLAY DREIDLE SOUND
	dreidlesound:Play()

	--moves the dreidle to the requested location
	dBody.CFrame = CFrame.fromEulerAnglesXYZ(0, 0, 0) + targetPos + Vector3.new(0, 2.5, 0)

	--adds a random rotation velocity with a slight downward angle to cause the dreidle to spin
	dBody.RotVelocity = Vector3.new(math.random(0, 7), math.random(20, 80), math.random(7, 9)) --set rotational velocity

	wait(2.8) -- delay to allow the dreidel to settle

	--identifies what face is up and what face is on bottom

	frontVector = dBody.CFrame:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Front))

	leftVector = dBody.CFrame:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Left))

	--dot product of the vectors with (0,1,0)
	test1 = frontVector.y
	test2 = leftVector.y

	--takes the largest y value and tests positive or negative to identify the 4 faces it could land on
	if math.abs(test1) > math.abs(test2) then
		if test1 > 0 then
			--print("Nun")
			count = 0
		else
			--print("Shin")
			count = 5
		end
	else
		if test2 > 0 then
			--print("Hey")
			count = 15
		else
			--print("Gimmel")
			count = 25
		end
	end

	-- generates the necissary number of coins and throws them a random distance from the dreidle

	--PLAY COIN SOUND
	coinsound:Play()

	for i = 1, count do
		local p = Instance.new("Part")
		p.BrickColor = BrickColor.new(23)
		p.formFactor = 2
		p.Size = Vector3.new(1, 0.2, 1)
		p.TopSurface = 0
		p.BottomSurface = 0

		local a = math.random() * 6.28 -- magic number??
		local d = Vector3.new(math.cos(a), 0, math.sin(a)).unit
		p.Velocity = d * 25
		p.RotVelocity = d
		p.Position = dBody.Position + Vector3.new(0, 2, 0) + Vector3.new(0, math.random() * 3, 0) + (d * 2)
		p.Parent = game.Workspace
		Tool.Mesh:Clone().Parent = p
		Tool.CoinScript:Clone().Parent = p

		debris:AddItem(p, 60)
	end

	Tool.Enabled = true
	Tool.Handle.Transparency = 0
end
