How do I make this work? It is an owner door for a tycoon and I can't tell what's wrong with it.
Asked by
4 years ago Edited 4 years ago
01 | local Essentials = script.Parent:WaitForChild( "Essentials" ) |
02 | local Door = Essentials:WaitForChild( "Door" ) |
03 | local DoorOwner = Door.Mainpiece:WaitForChild( "OwnerValueOfDoor" ) |
04 | local TycoonInfo = script.Parent:WaitForChild( "TycoonInfo" ) |
05 | local OwnerValue = TycoonInfo:WaitForChild( "Owner" ) |
07 | Door.MainPiece.Touched:connect( function (Hit) |
08 | if Hit and Hit.Parent and Hit.Parent:FindFirstChild( "Humanoid" ) then |
09 | local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) |
10 | if Player and OwnerValue.Value = = "" then |
11 | OwnerValue.Value = Player |
12 | if Player.Name = = OwnerValue.Value then |
13 | Door.MainPiece.CanCollide = false |
14 | Door.MainPiece.BillboardGui.OwnerLabel.Text = "Owner: " .. tostring (OwnerValue.Value.Name) |
I'm trying to make a claim door for a Roblox tycoon and currently, I'm stuck trying to figure out how to get it to update values. I want to be able to check if a player is the owner later on so that I can make it into an owner only door.
Edit: I forgot to say that currently I'm just trying to check if a door doesn't have an owner and if it doesn't I want the person touching it to become owner.
Edit 2: I just changed the code and did some testing. It isn't working on the part that checks if no owner. "if Player and OwnerValue.Value == "" then"
Final Edit/ Answer:
This is the answer and the solved code:
1 | game.Players.PlayerAdded:Connect( function (Player) |
2 | local TycoonNumber = Instance.new( "IntValue" ) |
3 | TycoonNumber.Name = "TycoonNumber" |
4 | TycoonNumber.Parent = Player |
in a serverscript and then after creating a bool called TycoonTaken:
01 | Door.MainPiece.Touched:Connect( function (Touch) |
02 | if Tycoon.TycoonTaken.Value = = false then |
03 | if game.Players:GetPlayerFromCharacter(Touch.Parent) then |
04 | local Player = game.Players:GetPlayerFromCharacter(Touch.Parent) |
05 | Player.TycoonNumber.Value = 1 |
06 | OwnerValue.Value = Player |
07 | Door.MainPiece.Transparency = 0.5 |
08 | Door.MainPiece.BillboardGui.OwnerLabel.Text = "Owner: " .. tostring (OwnerValue.Value.Name) |
09 | Door.MainPiece.CanCollide = false |
11 | elseif Tycoon.TycoonTaken.Value = = true then |
12 | if game.Players:GetPlayerFromCharacter(Touch.Parent) then |
13 | local Player = game.Players:GetPlayerFromCharacter(Touch.Parent) |
14 | if Player.TycoonNumber = = Tycoon.TycoonNumber.Value then |
Door being already declared and the mainpiece is the part with collision and color.