#Workspace.Tycoon.Tycoon.Script.Core:7: attempt to index nil with 'OwnerValue' - Server - Core:7

63 messages · Page 1 of 1 (latest)

coral plank
#

local tycoon = script.Parent.Parent

local mainItems = tycoon:FindFirstChild("MainItems")
local values = tycoon:FindFirstChild("Values")

mainItems.OwnerDoor.Door.Touched:Connect(function(hit)
if values.OwnerValue.Value == nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player:FindFirstChild("HasTycoon").Value == false then
values.OwnerValue.Value = player
mainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tostring(values.OwnerValue.Value).."'s Tycoon"
end
end
end
end)

#

here's the script

runic inlet
#

it means what it means

#

values is nil

sharp sigil
#

SIUUU

#

add a wait for child

#

also use guard clauses

#
local OwnerValue = values:WaitForChild("OwnerValue")

mainItems.OwnerDoor.Door.Touched:Connect(function(hit)
    if (OwnerValue.Value ~= nil) then return end

    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if (player == nil) then return end

    local hasTycoon = player:FindFirstChild("HasTycoon")
    if (hasTycoon == nil or hasTycoon.Value == true) then return end

    OwnerValue.Value = player
    mainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tostring(OwnerValue.Value).."'s Tycoon"
end)
unreal jolt
sharp sigil
#

look

#

how good

#

it looks now

#

:D

magic owl
#

what the hell is a guard clause

sharp sigil
#

see the difference

#

between ur code

#

and mine

#

or THE OP

#

code

#

idk whos code was that

#

its like negating the if conditions

#

and returning early

magic owl
#

their code looks more curvy fr

unreal jolt
#

guard clauses are way better than nested code

sharp sigil
#

it helps in making the code less nested

magic owl
sharp sigil
#

I would choose reading the second one over the first one

magic owl
sharp sigil
#

no because

#

its more

#

readable

#

second one

unreal jolt
#

intead of doing

if blabla
  if blagalg
    if hahaha
      --code
    end
  end
end
-- you do
if not blabla then return end
if not blagalg then return end
if not hahaha then return end
-- code
magic owl
#

yeah

sharp sigil
#

for tables

#

or loops in generale

#

by changing the return statement with continue

unreal jolt
#

i know mate

#

::continue::

#

::skip::

#

😉

sharp sigil
#

no

#

dont doesnt apply to LuaU

#

LuaU have own continue

unreal jolt
#

ahh yes

#

lua have just 'continue' keyword

outer turtleBOT
#

studio** You are now Level 4! **studio

sharp sigil
#

yes

unreal jolt
#

ur right

magic owl
#

@unreal jolt you might've just unintentionally saved my code

unreal jolt
#

lessgo

sharp sigil
#

how

#

lol

magic owl
#

with the return end

#

idk if it works with my script but

sharp sigil
#

guard clauses

#

?

magic owl
#

i need it to basically

#

look at my report for more info

#

in #1020374354867007528