Apparently with my script which keeps sending me errors even if I cant find one, mainly “Attempt to index nil with ‘FindFirstChild’”
script.Parent.SurfaceGui.Time.Changed:Connect(function()
if script.Parent.SurfaceGui.Time.Value < 1 then
local Player1 = script.Parent.Parent.AttackerTele.Person.Value
local Player2 = script.Parent.Parent.DefenderTele.Person.Value
Player1:FindFirstChild("HumanoidRootPart").CFrame = workspace.Defenderspawn.CFrame
Player2:FindFirstChild("HumanoidRootPart").CFrame = workspace.Attackerspawn.CFrame
wait(2)
script.Parent.Parent.DefenderTele.Person.Value = nil
script.Parent.Parent.AttackerTele.Person.Value = nil
script.Parent.Parent.AttackerTele.Peopleinroom.Value = 0
script.Parent.Parent.DefenderTele.Peopleinroom.Value = 0
end
end)
This is a Normal Script not a Local Script
1 Like
Player1 and Player2 doesn’t exist. At the time you check those values are not set. (Person.Value)
Sorry, but I dont understand what you meant by “At the time you check those values are not set”
They do not exist. AttackerTele.Person.Value is nil.
Right here this value is empty. This means that if I try to do this:
game:GetService("ServerScriptService"):WaitForChild("Value").Value:FindFirstChild("Hello")
It wont work since the “Value” property is empty. A way you can prevent the script from erroring is to add an if statement.
if Player1 then
end;
so for example an if statement to prevent this would be:
local Player1 = script.Parent.Parent.AttackerTele.Person.Value
local Player2 = script.Parent.Parent.DefenderTele.Person.Value
if(Player1 and Player2) then
Player1:FindFirstChild("HumanoidRootPart").CFrame = workspace.Defenderspawn.CFrame
Player2:FindFirstChild("HumanoidRootPart").CFrame = workspace.Attackerspawn.CFrame
wait(2)
script.Parent.Parent.DefenderTele.Person.Value = nil
script.Parent.Parent.AttackerTele.Person.Value = nil
script.Parent.Parent.AttackerTele.Peopleinroom.Value = 0
script.Parent.Parent.DefenderTele.Peopleinroom.Value = 0
end;
I tried that and there were no errors. Unfortunately, the script isn’t executed as intended
If the script is never executed then that means that the values are never set. They are either never set or the script runs before they are set.
What is this “AttackerTele” value?
AttackerTele.Person’s Value is an object value and it is usually the player’s character
When is “AttackerTele” set in the script? Is it another script?
From what im seeing in that script, youre getting a value, and then trying to get a HumanoidRootPart from a string, which will return nil.
Change HRP to CharacterRootPart
Save these as id and find from that
script.Parent.Parent.AttackerTele.Person.Value
script.Parent.Parent.DefenderTele.Person.Value
game.Workspace.Elevator.AttackerTele.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
game.Workspace.Elevator.AttackerTele.Person.Value = game.Workspace:FindFirstChild(hit.Parent)
end
end)
Well I am pretty sure that this person is using an object value, and even if they are not the error is indicating that the value itself is nil or else it would say something like “Attempting to index ‘FindFirstChild’ with string”
Here is the problem, you are trying to find the first child using an instance and not a string. Instead of hit.Parent do hit.Parent.Name
Also, the hit.Parent is the player, there is no need to search it in Workspace.
game.Workspace.Elevator.AttackerTele.Person.Value = hit.Parent;
There is an error “Attempt to index nil with ‘FindFirstChild’”
Could you tell me what line is causing the error?
Both line 6 and 7 are causing the problem
Can you send the content of those lines?
Player1:FindFirstChild("HumanoidRootPart").CFrame = workspace.Defenderspawn.CFrame
Player2:FindFirstChild("HumanoidRootPart").CFrame = workspace.Attackerspawn.CFrame
Are you running the script with the if statement? Or did you remove it?
If so did you ensure that you touched the Elevator.AttackerTele part?
2 Likes