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

Can I add a script that only allows a local player to own one house?

Asked by 6 years ago

Hello!

I utilized a tycoon door script to allow a local player to pick a particular home in a game:

--//Variables
local owner = script.Parent.OwnerName
local isOpen = false
local waitTime = 2
local door = script.Parent

--//Ensures that the door is closed
door.CanCollide = true
door.Transparency = 0
door.Anchored = true

script.Parent.Touched:connect(function(hit)
 local humanoid = hit.Parent:FindFirstChild("Humanoid")
 if humanoid then
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
  if plr then
   --//A player
   if owner.Value == "" then
    --//No Current Owner, set player as new owner
    owner.Value = plr.Name
   elseif plr.Name == owner.Value then
    --//The owner
    if isOpen == false then
     isOpen = true
     door.CanCollide = false
     door.Transparency = 0.8
     wait(waitTime)
     door.CanCollide = true
     door.Transparency = 0
     isOpen = false
    end
   else
    --//Not the owner
    humanoid.Health = 0 
   end
  end
 end
end)

This script works great but it allows the same player to take over as many properties as they want. Is there something I can add that will only allow them to get one house & prevent multiple ownerships?

I am trying to make sure they do not come in game and take multiple properties.

Thanks!

0
All you have is do is make a boolean that determines if the person has a building. So before the can create a building a script will check if the already have a building which will be determined by the boolean. :) IFeelLikeAGucciAdlib -2 — 6y

1 answer

Log in to vote
0
Answered by
SmartNode 383 Moderation Voter
6 years ago

To solve this problem, I would advise these things:

Before starting,

  • Place a BoolValue in the each house/property. Name: IsClaimed

  • Place another BoolValue, but this time in the player. Name: OwnsAHouse

When claiming a new property,

  • If the property is already claimed, (by telling if "IsClaimed" is true)

    • Error, and tell them that it's already claimed.
  • If the property is not claimed, (by telling if "IsClaimed" is false)

    • Make "IsClaimed" to true

    • Get the player,

      • Make "OwnsAHouse" to true
Ad

Answer this question