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.
You're better off assigning each tycoon a number value and giving each player a number value on spawn.
Script to give players Number Values on spawn
game.Players.PlayerAdded:Connect(function(Player) local TycoonNumber = instance.new("NumberValue") TycoonNumber.Name = TycoonNumber TycoonNumber.Parent = Player end)
Youd also want to give the tycoon a bool value named "TycoonClaimed" or something similar For example
--The tycoon number is 4 local Tycoon = game.Workspace.(TycoonModelHere) Tycoon.Door.Touched:Connect(function(Touch) if Tycoon.TycoonTaken.Value == false then if Touch.Parent:GetPlayerFromCharacter then Player = Touch.Parent:getPlayerFromCharacter Player.TycoonNumber.Value = 4 Tycoon.Door.Cancollide = false --You could also change transparency here end elseif Tycoon.TycoonTaken.Value == true then if Touch.Parent:GetPlayerFromChracter then Player = Touch.Parent:getPlayerFromCharacter if Player.TycoonNumber == Tycoon.TycoonNumber.Value then end else Touch.Parent.Humanoid.Health = 0 end end)
This script should check if the base is taken, and if it is then check if the touch is the owner or not.
Comment if you find any errors.
If this helped please consider marking it as the answer.
Line 8 you have PLayers instead of Players