local Essentials = script.Parent:WaitForChild("Essentials")
local Door = Essentials:WaitForChild("Door")
local DoorOwner = Door.Mainpiece:WaitForChild("OwnerValueOfDoor")
local TycoonInfo = script.Parent:WaitForChild("TycoonInfo")
local OwnerValue = TycoonInfo:WaitForChild("Owner")
Door.MainPiece.Touched:connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player and OwnerValue.Value == "" then
OwnerValue.Value = Player
if Player.Name == OwnerValue.Value then
Door.MainPiece.CanCollide = false
Door.MainPiece.BillboardGui.OwnerLabel.Text = "Owner: " .. tostring(OwnerValue.Value.Name)
end
end
end
end)
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:
game.Players.PlayerAdded:Connect(function(Player)
local TycoonNumber = Instance.new("IntValue")
TycoonNumber.Name = "TycoonNumber"
TycoonNumber.Parent = Player
end
in a serverscript and then after creating a bool called TycoonTaken:
Door.MainPiece.Touched:Connect(function(Touch)
if Tycoon.TycoonTaken.Value == false then
if game.Players:GetPlayerFromCharacter(Touch.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Touch.Parent)
Player.TycoonNumber.Value = 1
OwnerValue.Value = Player
Door.MainPiece.Transparency = 0.5
Door.MainPiece.BillboardGui.OwnerLabel.Text = "Owner: " .. tostring(OwnerValue.Value.Name)
Door.MainPiece.CanCollide = false--You could also change transparency here
end
elseif Tycoon.TycoonTaken.Value == true then
if game.Players:GetPlayerFromCharacter(Touch.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Touch.Parent)
if Player.TycoonNumber == Tycoon.TycoonNumber.Value then
end
--else
--Touch.Parent.Humanoid.Health = 0
end
end
end)
Door being already declared and the mainpiece is the part with collision and color.

1 comment
Does putting Player.Name help?