Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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
01local Essentials = script.Parent:WaitForChild("Essentials")
02local Door = Essentials:WaitForChild("Door")
03local DoorOwner = Door.Mainpiece:WaitForChild("OwnerValueOfDoor")
04local TycoonInfo = script.Parent:WaitForChild("TycoonInfo")
05local OwnerValue = TycoonInfo:WaitForChild("Owner")
06 
07Door.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)
15            end
16        end
17    end
18end)

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:

1game.Players.PlayerAdded:Connect(function(Player)
2    local TycoonNumber = Instance.new("IntValue")
3    TycoonNumber.Name = "TycoonNumber"
4    TycoonNumber.Parent = Player
5end

in a serverscript and then after creating a bool called TycoonTaken:

01Door.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--You could also change transparency here
10        end
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
15 
View all 21 lines...

Door being already declared and the mainpiece is the part with collision and color.

0
Does putting Player.Name help? FrontalDev 17 — 4y

2 answers

Log in to vote
0
Answered by
Wayyllon 170
4 years ago

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

1game.Players.PlayerAdded:Connect(function(Player)
2    local TycoonNumber = instance.new("NumberValue")
3    TycoonNumber.Name = TycoonNumber
4    TycoonNumber.Parent = Player
5end)

Youd also want to give the tycoon a bool value named "TycoonClaimed" or something similar For example

01--The tycoon number is 4
02local Tycoon = game.Workspace.(TycoonModelHere)
03 
04Tycoon.Door.Touched:Connect(function(Touch)
05    if Tycoon.TycoonTaken.Value == false then
06        if Touch.Parent:GetPlayerFromCharacter then
07            Player = Touch.Parent:getPlayerFromCharacter
08            Player.TycoonNumber.Value = 4
09            Tycoon.Door.Cancollide = false
10            --You could also change transparency here
11        end
12    elseif Tycoon.TycoonTaken.Value == true then
13        if Touch.Parent:GetPlayerFromChracter then
14        Player = Touch.Parent:getPlayerFromCharacter
15        if Player.TycoonNumber == Tycoon.TycoonNumber.Value then
View all 21 lines...

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.

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. odieosus 8 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Line 8 you have PLayers instead of Players

0
Yea I just rewrote the code and edited it a bit and I am going to put that instead odieosus 8 — 4y

Answer this question