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

Help with handle error?

function evalKill(hit)
	if slashing then
		if hit.Parent~=nil and hit.Parent:FindFirstChild("Humanoid")~=nil and hit.Parent.Humanoid.Health>0 and not hit:IsDescendantOf(script.Parent.Parent) then
			if hit.Parent:FindFirstChild("Head")~=nil then
				for _,s in ipairs(hit.Parent.Head:GetChildren()) do
					if s.className=="Sound" then
						s:Remove()
					end
				end
				script.Parent.Handle.Kill:Clone().Parent = hit.Parent.Head
				hit.Parent.Head.Kill:Play()
				game.Debris:AddItem(hit.Parent.Head.Kill,2)
			end
			hit.Parent.Humanoid:TakeDamage(100)
		end	
	end
end

script.Parent:FindFirstChild("Handle").Touched:connect(evalKill) -- ERROR HERE

Error Client 21:48:15.382 - Players.Player1.Backpack.Knife.LocalScript:133: attempt to index a nil value This seems to have the error. I don't understand how it is a 'nil' value, as the script.Parent does have a Handle inside it, so I don't see why this should be breaking.

It seems to work perfectly on studio, but not when I have a server running.

1 comment

0

:FindFirstChild("") method finds the child. If the child can not be found, it will return nil. It's probably reading nil, so maybe use :WaitForChild() in place of :FindFirstChild()

1 answer

✓ Accepted answer

Problem

The only problem I can see is that since it works in studio and not in server it should be a latency problem, this happens because in studio everything is pretty much local so you don't have to wait for a server to create stuff so your local scripts run instantly. In server this doesn't happen as when a local scripts cause upons something in player or character that is server-sided then the local script is "local" which makes it run faster then the server can respond.

Solution

repeat wait() until game.Players.LocalPlayer.Character--To the top of every local script

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