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

error when i run this code to change the player's Respawn Location. can yall help me with that?

Asked by 2 years ago

so im trying to make the player change his respawn location but i get this error for some reason: Players.Medoozi.PlayerGui.InsertedObjects.ObbyButton.Script:10: attempt to index nil with 'FindFirstChild'

local players = game:GetService("Players")
local Cpoints = game.Workspace.CheckPoints:GetChildren()
local obbyv =  script.Parent.Value
local tycoonv =  script.Parent.Parent.TycoonButton.Value
local Teams = game:GetService("Teams")
local player = players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function(player)

--local player = players.LocalPlayer
local leaderstats = player:FindFirstChild("leaderstats")
local Stage = leaderstats:FindFirstChild("Stage")
if player.Team == Teams.Red then
    obbyv.Value = true
    tycoonv.Value = false
    if obbyv.Value == true then

        player.RespawnLocation = Cpoints[Stage.Value]


        script.Parent.BackgroundColor3 = Color3.new(0.545098, 0.545098, 0)
        script.Parent.Shadow.BackgroundColor3 = Color3.new(0.282353, 0.282353, 0)

        script.Parent.Parent.TycoonButton.BackgroundColor3 = Color3.new(255, 0, 0)
        script.Parent.Parent.TycoonButton.Shadow.BackgroundColor3 = Color3.new(0.290196, 0, 0)

    end
end

Answer this question