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

How to find if player is owner?

Asked by 8 years ago

So, I have a Tycoon type claiming system for a house. When the user hits the brick, it's their house. Now I need to check if the user owns that house. Not sure how to do that.

Claiming Script:

local ting = 0 --debouncer
owner = script.Parent.Parent.Parent.OwnerName --This is the thing that holds the owners name

function onTouched(hit)

    if ting == 0 then --debounce check
    ting = 1 --activate debounce
    check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button

    if check ~= nil then --If a human is found, then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players
        if (user:FindFirstChild("House1") ~= nil) then 

        local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players
        local message = Instance.new("Message") --make a message
        message.Text = "You already own a House" --Put text into the message
        message.Parent = user --Display message to new owner only
        wait(3) --Wait to let the message display for a while
        message:remove() --Remove the message from the new owner

        else

        local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players
        owner.Value = hit.Parent.Name --save new owners name for later.

        local own = Instance.new("IntValue")
        own.Name = "House1"
        own.Parent = user

        local message = Instance.new("Message") --make a message
        message.Text = "You now own this House!" --Put text into the message
        message.Parent = user --Display message to new owner only
        wait(3) --Wait to let the message display for a while
        message:remove() --Remove the message from the new owner

        script.Parent.Parent:remove()

        end
    end
    ting = 0 --remove debounce
    end

end

script.Parent.Touched:connect(onTouched) --Start listening for button-touchers.

This is where the Check for owner will go

function onButton1Down(mouse)
    if m ~= nil and mouse.target == game.Workspace.House1.Floor then -- insert and [CODE] after House1.Floor
        g = m:GetChildren()

The code would need to be inserted after the game.Workspace.House.Floor.

Answer this question