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
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.
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
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
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…
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:
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)
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.
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)