Spit script not working?

So I have a spit script that is an emote, you type /e spit and it spits. And it works perfectly fine in studio, but once you get into a real game, its not working? Taking a look where you see any reasons why? The issue being that you do the emote, and it will show the “spit” 30 studs away. And it does not do this in studio.

local re = Instance.new("RemoteEvent",game.ReplicatedStorage)
re.Name = "Spit"

re.OnServerEvent:Connect(function(player)
	local character = player.Character
	wait(0.9)
	print("character loaded")
								repeat
									wait(0.1)
								local p = Instance.new("Part",character)
								p.CanCollide = false
									print("part created and collide off")
								local color = math.random(1, 3)
								local bcolor
								if color == 1 then
									bcolor = BrickColor.new(11)
								elseif color == 2 then
									bcolor = BrickColor.new(1013)
								elseif color == 3 then
									bcolor = BrickColor.new(329)
								end
								p.BrickColor = bcolor
									print("given colors")
								local m = Instance.new('BlockMesh',p)
								p.Size = Vector3.new(0.2,0.2,0.2)
								m.Scale = Vector3.new(1*0.9, 1*0.9, 1*0.9)
								p.Locked = true
								p.CanCollide = false
								p.TopSurface = "Smooth"
								p.Material = Enum.Material.Neon
								p.BottomSurface = "Smooth"
								p.CFrame = character.Head.CFrame * CFrame.new(Vector3.new(0, 0, -1))
								p.Velocity = character.Head.CFrame.lookVector * 20 + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5))
								p.Anchored = false
								m.Name = 'Puke Peice'
								p.Name = 'Puke Peice'
									print("last thing")
									until run == false
									end)
						wait(0.4)
						run = false
2 Likes

Well no, it’s supposed to fall and destroy, but it’s not coming in the right position, which is supposed to be the players head, and like said before is like 30 studs away instead.

have you tried it without the loop?

local re = Instance.new(“RemoteEvent”,game.ReplicatedStorage)
re.Name = “Spit”

re.OnServerEvent:Connect(function(player)
	local character = player.Character
	wait(0.4)
		local p = Instance.new("Part",character)
		p.CanCollide = false
		print("part created and collide off")
		local color = math.random(1, 3)
		local bcolor
		if color == 1 then
			bcolor = BrickColor.new(11)
		elseif color == 2 then
			bcolor = BrickColor.new(1013)
		elseif color == 3 then
			bcolor = BrickColor.new(329)
		end
		p.BrickColor = bcolor
		print("given colors")
		local m = Instance.new('BlockMesh',p)
		p.Size = Vector3.new(0.2,0.2,0.2)
		m.Scale = Vector3.new(1*0.9, 1*0.9, 1*0.9)
		p.Locked = true
		p.CanCollide = false
		p.TopSurface = "Smooth"
		p.Material = Enum.Material.Neon
		p.BottomSurface = "Smooth"
		p.CFrame = character.Head.CFrame * CFrame.new(Vector3.new(0, 0, -1))
		p.Velocity = character.Head.CFrame.lookVector * 20 + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5))
		p.Anchored = false
		m.Name = 'Puke Peice'
		p.Name = 'Puke Peice'
		print("last thing")
end)