How Do I Make This Work?

Hey!

I’m working on a tycoon game & I was wondering if anyone could help me with this code?

I don’t have much experience with scripting & I want to make this with 0 tutorials involved.

I have this script which allows the player to claim the tycoon & nobody else can claim it until that player leaves the game.

image

I scripted it so that it works with teams but I was wondering if anyone knows how I make it so that only the player on that team can do stuff in the tycoon. For example, only the player in the team can open the owner door.

I’m assuming I probably have to do a lot more then just the door as there’s going to be 6 of the same tycoon duplicated & I think that might break the game.

If anybody can help me fix this & get the tycoons working correctly, I’d appreciate it a lot.

3 Likes

You could try this:

local Teams = game:GetService("Teams")

if player.Team = Teams["Put team name here"] then
    -- do stuff
end
2 Likes

I tested it & it doesn’t work.

Forgot to add an extra equal sign. Try:

local Teams = game:GetService("Teams")

if player.Team == Teams["Put team name here"] then
    -- do stuff
end
2 Likes

Do I need to make a player variable?

image

Yes. You could use the currentplayer value.

local player = game.Players:FindFirstChild(currentPlayer.Value)
1 Like

Here’s the code:

It errored because currentPlayer has no value, which can make player nil. You could do this:

local currentPlayer = -- path to currentplayer value in owner door
local Teams = game:GetService("Teams")
local player = game.Players:FindFirstChild(currentPlayer.Value)

if player then
    if player.Team == Teams["Programmer 1"] then
        -- do stuff
    end
end

image

You have to get the path to the currentPlayer value inside your owner door. For example,

local currentPlayer = game.Workspace.Tycoon.OwnerDoor.CurrentPlayer 

(dont use this, it is just an example.)

Ohhh alright sorry I’m an idiot lol.