Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

works in studio but not in multiplayer?

targetPos = game.Players.LocalPlayer.Character.Humanoid.TargetPoint
lookAt = (targetPos - game.Players.LocalPlayer.Character.Head.Position).unit
d = true
script.Parent.Equipped:connect(function(mouse)
	mouse.Button1Down:connect(function()
		if d == true then
			d = false
		targetPos = game.Players.LocalPlayer.Character.Humanoid.TargetPoint
		lookAt = (targetPos - game.Players.LocalPlayer.Character.Head.Position).unit
		local p = Instance.new("Part")
		p.Position = script.Parent.Handle.Position
		p.Parent = game.Workspace
		p.CanCollide = true
		p.Name = script.Parent.Parent.Name
		p.Size = Vector3.new(.4,.4,.4)
		p.BrickColor = BrickColor.new("New Yeller")
		p.Velocity = lookAt * 300--script.Parent.Parent.Torso.CFrame.lookVector * 500
		local Bforce = Instance.new("BodyForce", workspace)
    	Bforce.Parent = p
    	Bforce.force = Vector3.new(0, 196.2, 0) * p:GetMass()
		local s = game.ReplicatedStorage.hit:Clone()
		s.Parent = p
		s.Disabled = false
		game:GetService("Debris"):AddItem(p, 5)
		wait(.5)
		d = true
		end
	end)
end)

it's a working gun script. works fine in studio, but in muliplayer, i get this in the console:

Something about Character being nil

i add a wait(1) at the start, and nothing in the console, but the damaging still doesnt work, heres the damage script:

script.Parent.Touched:connect(function(hit)
	local e = script.Parent.Name
	local p = game.Players:FindFirstChild(e)
	if hit:IsDescendantOf(p.Character) then
		local l = 0
	elseif hit.Parent.Humanoid ~= nil and hit.Name ~= "Head" then
		local q = Instance.new("Part")
	q.Shape = "Ball"
	q.Size = Vector3.new(.4,.4,.4)
	q.BrickColor = BrickColor.new("Really red")
	q.CanCollide = false
	q.Parent = game.Workspace
	q.Position = script.Parent.Position
	local e = game.ReplicatedStorage.hit2:Clone()
	e.Parent = q
		print(hit.Name)
		script.Parent:Destroy()
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 30
	elseif hit.Parent.Humanoid ~= nil and hit.Name == "Head" then
	local w = Instance.new("Part")
	w.Shape = "Ball"
	w.Size = Vector3.new(.4,.4,.4)
	w.BrickColor = BrickColor.new("Really red")
	w.CanCollide = false
	w.Parent = game.Workspace
	w.Position = script.Parent.Position
	local r = game.ReplicatedStorage.hit2:Clone()
	r.Parent = w
		script.Parent:Destroy()
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 60
	end
end)

this one gets cloned into the part that is made form the gun. since it doesnt damage my test humanoid, or make the blood(the e and r vars, look at those) appear, i'm assuming its in the gun script. anybody have anything? the scripts that get cloned into instance.new parts are called hit for the damage, and hit2 for the blood. they are both server scripts, and they both are in replicated storage.

1 answer

I've noticed on several of these questions, the same problem. Try using WaitForChild().

3 comments

0

what would i use :WaitForChild() on?

0

Such as: game.Players.LocalPlayer:WaitForChild("Character"). I recommend doing it for all variables @theCJarmy7

0

ok, ill tryit

This discussion is preserved as it was. New answers, comments, and votes are closed.