Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make this work? It is an owner door for a tycoon and I can't tell what's wrong with it.

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

0

Does putting Player.Name help?

2 answers

✓ Accepted answer

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.

1 comment

0

There were a few typos (The GetPlayerFromCharacter's didn't have the () of a function) but other than that after changing some values this seems to work. Thank you! Edit: One error was that you have to change the Touch.Parent:GetPlayerFromCharacter() to game.Players:GetPlayerFromCharacter(Touch.Parent)         OK so turns out there were a few more errors and I'm going to post that final code.

Line 8 you have PLayers instead of Players

1 comment

0

Yea I just rewrote the code and edited it a bit and I am going to put that instead

This discussion is preserved as it was. New answers, comments, and votes are closed.