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

why do I get a error in game but not in studio it says that line 13 cant destroy a nil?

Asked by 3 years ago
Edited 3 years ago
local plr = script.Parent.Parent.Parent.Parent.Parent
local Clicked = false

script.Parent.MouseButton1Click:Connect(function()
    local Twoplayers = math.random(1,2)
    local Threeplayers = math.random(1,3)
    local Fourplayers = math.random(1,4)
    local TableOfPlayers = game.Players:GetPlayers()
    script.Parent.Parent.Parent.Enabled = false
    if Clicked == false then
        Clicked = true
        for i = 0, 5 do
            local block = game.Workspace.Blocks:FindFirstChild(plr.Name)
            block:Destroy()
            Clicked = false
        end 
    end

Error is on line 13

2 answers

Log in to vote
0
Answered by 3 years ago

i think you have to put it as:

local block = game.Workspace.Blocks:FindFirstChild(tostring(plr.Name))

im not 100% sure it will work but yeah

0
Alright will try vortex767 20 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I found the answer it was a mistake with naming the cubes. Sorry for wasting anytime and thank you for anyone that helped me! and remember to always check over your code.

Answer this question