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

How do you assign an owner to a tycoon and call upon them in script?

So I've just got into scripting and I am trying to make my first tycoon. I'm not sure how to assign the owner of the tycoon to a variable and call upon it when they make purchases. I have the leaderboard running, however whenever I try to put the "Owner" variable in place of my name it says that "Owner" is not a player. I've been looking for a solution for a few hours but I can't seem to find it. If I could find a fix to this it would solve all of my problems.

Here's the code I'm using now


local owner = game.workspace.tycoon.StartingScript
local function steppedOn2(part)
	
	local player = part.Parent
	if game.Players:GetPlayerFromCharacter(player) then
		local player = game.getPlayerFromName(owner)
		if game.Players.owner.leaderstats.Cash.Value >= 50 then
		game.Players.owner.leaderstats.Cash.Value = game.Players.owner.leaderstats.Cash.Value - 50
		Cannon.Parent = game.Workspace.Tycoon
		CannonPad:Destroy()
	end
end
end

CannonPad.Touched:connect(steppedOn2)

Thanks for the help

2 answers

✓ Accepted answer

you did not define owner.... how do you expect roblox to magically guess the "owner" and you only use your own username in line 7.

here is an actual working version of that.

local function steppedOn2(part)

    if game:GetService'Players':GetPlayerFromCharacter(part.Parent) then
        local player = game.GetPlayerFromCharacter(part.Parent)
        if player.leaderstats.Cash.Value >= 50 then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 50
        Cannon.Parent = workspace.Tycoon
        CannonPad:Destroy()
end
end
end --end of function

CannonPad.Touched:connect(steppedOn2)

also

9 comments

0

correct

0

yep

0

Sorry, I accidentally posted what I was originally using. I've fixed it to call upon the variable used in the starting script

0

see if this works

0

also on the new script you posted owner is not used correctly, you'd have to use game.Players[owner.Value]

0

Thanks! This fixed my problem

0

Line 3 is unnecessary. Obviously it has a parent. Else the code couldn’t run since the part didn’t exist.

0

Yeah I realized that, my bad.

0

deleted

###The script won’t know if you’re the owner. You’ll have to do something like this:

local plrs = game:GetService"Players"

local function steppedOn2(part)
    local plr = plrs:GetPlayerFromCharacter(part.Parent)
    
    if plr then
        if plr.UserId == game.CreatorId then 
            -- your code here
        end
    end
end

###DataModel.CreatorId holds a read-only int64 number. This is the UserId of the owner.

3 comments

0

What is the CreatorId?

0

CreatorId is the UserId of the creator of the place.

0

It’s a property of game

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