Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with handle error?

Asked by 8 years ago
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.

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() Redbullusa 1580 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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
Ad

Answer this question