Why doesn't this script work, I even checked if the thing that touches has a humanoid, and even with adding that - I get the same error I had. But why? Why do I even get an error without touching the flag? Here is the script:
script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then local player = game.Players:GetPlayerFromCharacter(humanoid.Parent) if player.Team.Name == "Wave" and humanoid.Parent:FindFirstChild("Invincibility") == false then script.Parent.Parent = humanoid.Parent local head = humanoid.Parent.Head script.Parent.CFrame = head.CFrame * CFrame.new(0,2,0) local weld = Instance.new("Weld") weld.Part0 = head weld.C0 = head.CFrame:inverse() weld.Part1 = script.Parent weld.C1 = script.Parent.CFrame:inverse() weld.Parent = script.Parent script.Parent.Anchored = false end end end) func = script.Parent.RemoveWeld function func.OnInvoke() print(1) end
Why doesn't it work, and why do I get an error without touching the brick??
Your problem is that you automatically assume that every humanoid has a player attached to it. That is wrong. You need to check if game.Players:GetPlayerFromCharacter(part.Parent) then
local player =game.Players:GetPlayerFromCharacter(part.Parent)
end
Hope that helps. If it doesn't, I'll run some tests once I get home and take a closer look at it.