#my script for a owner door isn't working

1 messages · Page 1 of 1 (latest)

north fog
#

im trying to make a tycoon game but for some reason the owner door isnt working. `` here is the script for people who are lazy to write it down

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
end
end
end
end) ``

north fog
ripe vapor
#
local Players = game:GetService("Players")
local Tycoon = script.Parent.Parent
local MainItems = Tycoon:FindFirstChild("MainItems")
local Values = Tycoon:FindFirstChild("Values")

local function OnTouched(otherPart: BasePart)
   local Player = Players:GetPlayerFromCharacter(otherPart.Parent)
   if not Player then return end
   if Values.OwnerValue.Value ~= nil then return end
   if Player.HasTycoon.Value then return end
   Values.OwnerValue.Value = Player
   Player.HasTycoon.Value = true
end

MainItems.OwnerDoor.Door.Touched:Connect(OnTouched)
#

You should look into using CollectionService for scripts like these, because I can tell with the way you wrote it that you have this exact same script copy and pasted throughout several Tycoon models

solar pelicanBOT
#

studio** You are now Level 1! **studio

ripe vapor
#

Which one?

ripe vapor
#

Is there an error I can look at?

north fog
ripe vapor
#

In your script output, if there was an error thrown by the script you put that code in, it would show in bold red text

solar pelicanBOT
#

studio** You are now Level 3! **studio

north fog
#

ok let me put the script back in

north fog
ripe vapor
#

There was an assignment on that line. Are you sure this is the right script?

ripe vapor
#

It's probably because I typed it on mobile without using proper tabs

#

I guess I can't really help in that regard

north fog
ripe vapor
#

If it doesn't then that means the error isn't coming from that code

north fog
ripe vapor
#

The script output

north fog
#

this?
``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
            end
        end
    end
end)``
ripe vapor
#

Your output should look something like this

north fog
solar pelicanBOT
#

studio** You are now Level 2! **studio

ripe vapor
north fog
ripe vapor
#

Try doing it and see if anything happens

north fog
ripe vapor
#

So there is no error

#

Does the script work?

north fog
ripe vapor
#

How do you know?

north fog
ripe vapor
#
local Players = game:GetService("Players")
local Tycoon = script.Parent.Parent
local MainItems = Tycoon:FindFirstChild("MainItems")
local Values = Tycoon:FindFirstChild("Values")

local function OnTouched(otherPart: BasePart)
   local Player = Players:GetPlayerFromCharacter(otherPart.Parent)
   
   if not Player then
      print("Could not find a player")
      return
   end
   
   if Values.OwnerValue.Value ~= nil then
      print("The tycoon is already owned by another player")
      return
   end
   
   if Player.HasTycoon.Value then
      print(`{Player.Name} already owns a tycoon`)
      return
   end
   
   Values.OwnerValue.Value = Player
   Player.HasTycoon.Value = true
   print(`{Player.Name} has successfully claimed a tycoon`)
   
end

MainItems.OwnerDoor.Door.Touched:Connect(OnTouched)

If all else fails, replace the script with this. It should tell you why it's not working if it isn't

north fog
ripe vapor
#

I didn't know there was such a script, and I didn't intend on helping that much further

north fog
ripe vapor
#

It's fine

north fog
ripe vapor
#

Yes

north fog
ripe vapor
#

That's strange

ripe vapor
solar pelicanBOT
#

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

ripe vapor
#

It has print statements to let you know why the script possibly isn't working

ripe vapor
#

Did it print anything?

north fog
ripe vapor
#

Wth

#

Ok

#

Is there a red underline anywhere in the script?

#

If so where?

north fog
#

im not getting any

solar pelicanBOT
#

studio** You are now Level 3! **studio

north fog
ripe vapor
#

No that should just be something the script editor has by default

#

Usually for an error like that, there is supposed to be a red underline under the problematic line(s) of code

north fog
ripe vapor
#

Ok, what was it?

north fog
ripe vapor
#

Oh

north fog
# ripe vapor Oh

what this for
MainItems.OwnerDoor.Door.Touched:Connect(OnTouched)

ripe vapor
#

Whenever OwnerDoor gets touched, it calls the OnTouched function

north fog
ripe vapor
#

It has to be after the OnTouched function has been declared or the script won't know what OnTouched is

north fog
#

so this part ``local function OnTouched(otherPart: BasePart)
local Player = Players:GetPlayerFromCharacter(otherPart.Parent)

if not Player then
    print("Could not find a player")
    return
end

if Values.OwnerValue.Value ~= nil then
    print("The tycoon is already owned by another player")
    return
end

if Player.HasTycoon.Value then
    print(`{Player.Name} already owns a tycoon`)
    return
end

Values.OwnerValue.Value = Player
Player.HasTycoon.Value = true
print(`{Player.Name} has successfully claimed a tycoon`)

end``

ripe vapor
#

Yes

north fog
ripe vapor
#

The parent of otherPart

north fog
ripe vapor
#

The part that touched the door

north fog
ripe vapor
#

Me neither

north fog
north fog
ripe vapor
#

Wdym

north fog
ripe vapor
#

Objectvalue