Script not working, any help?

So I have this script that should when the player joins, make them “puke” but it does not work after I have sat here and edited it, any help? There are no output errors and no signs of anything going wrong.

server = nil
service = nil
cPcall = nil
Pcall = nil
Routine = nil
GetEnv = nil
logError = nil
sortedPairs = nil
local Players = game:GetService("Players")

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:Connect(function(character) 
								wait(0.15)
								local p = Instance.new("Part",character)
								p.CanCollide = false
								local color = math.random(1, 3)
								local bcolor
								if color == 1 then
									bcolor = BrickColor.new(192)
								elseif color == 2 then
									bcolor = BrickColor.new(28)
								elseif color == 3 then
									bcolor = BrickColor.new(105)
								end
								p.BrickColor = bcolor
								local m = Instance.new('BlockMesh',p)
								p.Size = Vector3.new(0.1,0.1,0.1)
								m.Scale = Vector3.new(math.random()*0.9, math.random()*0.9, math.random()*0.9)
								p.Locked = true
								p.TopSurface = "Smooth"
								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'
								p.Touched:connect(function(o)
									if o and p and (not Players:FindFirstChild(o.Parent.Name)) and o.Name~='Puke Peice' and o.Name~='Blood Peice' and o.Name~='Blood Plate' and o.Name~='Puke Plate' and (o.Parent.Name=='Workspace' or o.Parent:IsA('Model')) and (o.Parent~=p.Parent) and o:IsA('Part') and (o.Parent.Name~= player.Character.Name) and (not o.Parent:IsA('Accessory')) and (not o.Parent:IsA('Tool')) then
										local cf = CFrame.new(p.CFrame.X,o.CFrame.Y+o.Size.Y/2,p.CFrame.Z)
										p:Destroy()
										local g=Instance.new('Part',Instance.Workspace)
										g.Anchored=true
										g.CanCollide=false
										g.Size=Vector3.new(0.1,0.1,0.1)
										g.Name='Puke Plate'
										g.CFrame=cf
										g.BrickColor=BrickColor.new(119)
										local c=Instance.new('CylinderMesh',g)
										c.Scale=Vector3.new(1,0.2,1)
										c.Name='PukeMesh'
										wait(10)
										g:Destroy()
									elseif o and o.Name=='Puke Plate' and p then 
										p:Destroy() 
										o.PukeMesh.Scale=o.PukeMesh.Scale+Vector3.new(0.5,0,0.5)
									end
								end)
end)
end)
						wait(10)
						run = false

Oh man, the spacing.

Isn’t the script disabled? Include more information.
Try printing through script as debugging.

The script is not disabled, no errors, and basically im trying to get it so when the player joins, it makes them throw up, but this is not working and I have no reason to see why.

As I said, try printing through the script to find out, where the script stops.
Also PlayerAdded event is ran only once!

I think you should check your conditional structure inside p.Touched, it’s very large:

if 
	o and p and 
	(not Players:FindFirstChild(o.Parent.Name)) and 
	o.Name ~= 'Puke Peice' and 
	o.Name ~= 'Blood Peice' and 
	o.Name ~= 'Blood Plate' and 
	o.Name ~= 'Puke Plate' and 
	(o.Parent.Name == 'Workspace' or o.Parent:IsA('Model')) and 
	(o.Parent ~= p.Parent) and 
	o:IsA('Part') and 
	(o.Parent.Name ~= player.Character.Name) and 
	(not o.Parent:IsA('Accessory')) and 
	(not o.Parent:IsA('Tool')) 
then

So I ran this.

local Players = game:GetService("Players")

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:Connect(function(character)
	print("character loaded")
								wait(1.15)
								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(192)
								elseif color == 2 then
									bcolor = BrickColor.new(28)
								elseif color == 3 then
									bcolor = BrickColor.new(105)
								end
								p.BrickColor = bcolor
									print("given colors")
								local m = Instance.new('BlockMesh',p)
								p.Size = Vector3.new(0.1,0.1,0.1)
								m.Scale = Vector3.new(math.random()*0.9, math.random()*0.9, math.random()*0.9)
								p.Locked = true
								p.TopSurface = "Smooth"
								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")
								p.Touched:connect(function(o)
									if player == player then
										local cf = CFrame.new(p.CFrame.X,o.CFrame.Y+o.Size.Y/2,p.CFrame.Z)
										p:Destroy()
										local g = Instance.new('Part',Instance.Workspace)
										g.Anchored = true
										g.CanCollide = false
										g.Size = Vector3.new(0.1,0.1,0.1)
										g.Name = 'Puke Plate'
										g.CFrame = cf
										g.BrickColor = BrickColor.new(119)
										local c = Instance.new('CylinderMesh',g)
										c.Scale = Vector3.new(1,0.2,1)
										c.Name='PukeMesh'
										wait(10)
										g:Destroy()
										print("touched and gave mesh")
									elseif o and o.Name=='Puke Plate' and p then 
										p:Destroy() 
										o.PukeMesh.Scale=o.PukeMesh.Scale+Vector3.new(0.5,0,0.5)
									end
								end)
end)
end)
						wait(10)
						run = false

and it stops somewhere between the “last thing” and the “touched and gave mesh” prints

Does g between those two statements actually get destroyed? Does it get instantiated at all?

I forgot to wait 10 seconds, I will go redo this.

1 Like

As I suspected, it works, so whats going wrong here?

Well, what happens to g between those two print statements? Does it just not spawn? Does it get destroyed?
Is the touched event just not firing? You probably can’t answer that…

Im not sure to be honest, but the puke should still be showing up, correct? Becuase nothing happens, 0.

1 Like

I don’t think Instance.Workspace is an actual property of Instance, not Workspace, so it’s returning nil.
Try changing this, 4th line of the p.Touched function:

local g = Instance.new('Part',Instance.Workspace)

to this:

local g = Instance.new('Part', workspace)

Im still not “puking” though. I have no clue still as to why.

1 Like

I do believe this fixed one issue though.

I noticed that your definition for cf is wrong, since CFrame values don’t have X Y and Z components.
Try changing this, 2nd line of p.Touched function:

local cf = CFrame.new(p.CFrame.X,o.CFrame.Y+o.Size.Y/2,p.CFrame.Z)

To this:

local cf = CFrame.new(p.Position.X, o.Position.Y + o.Size.Y/2, p.Position.Z)

So I get the “pukeplate” but I do not get the actual puke? Whats going on

I think you should try offsetting the puke’s starting CFrame by a bit more, just to make sure it’s not hitting anything.

Other than that, I tested the script myself and it seems like its working, it’s just hard to catch all the small parts.

The loading screen is hard-coded to be there for 5 seconds in Studio, so you could make the server script wait 5 seconds instead of the 1.15 you have currently.

I just tested it and only got 1 piece of vomit??

It looks like you just coded it to vomit only one piece? If you want more pieces you could just do a for loop or something like that.
Maybe something like:

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait(6)
		for i = 1, 10 do
			-- vomit code here
			wait(0.1)
		end
	end)
end)

I am confused, im not very good with that stuff, any way to possibly help?