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
01 | local owner = game.workspace.tycoon.StartingScript |
02 | local function steppedOn 2 (part) |
03 |
04 | local player = part.Parent |
05 | if game.Players:GetPlayerFromCharacter(player) then |
06 | local player = game.getPlayerFromName(owner) |
07 | if game.Players.owner.leaderstats.Cash.Value > = 50 then |
08 | game.Players.owner.leaderstats.Cash.Value = game.Players.owner.leaderstats.Cash.Value - 50 |
09 | Cannon.Parent = game.Workspace.Tycoon |
10 | CannonPad:Destroy() |
11 | end |
12 | end |
13 | end |
14 |
15 | CannonPad.Touched:connect(steppedOn 2 ) |
Thanks for the help
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.
01 | local function steppedOn 2 (part) |
02 |
03 | if game:GetService 'Players' :GetPlayerFromCharacter(part.Parent) then |
04 | local player = game.GetPlayerFromCharacter(part.Parent) |
05 | if player.leaderstats.Cash.Value > = 50 then |
06 | player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 50 |
07 | Cannon.Parent = workspace.Tycoon |
08 | CannonPad:Destroy() |
09 | end |
10 | end |
11 | end --end of function |
12 |
13 | CannonPad.Touched:connect(steppedOn 2 ) |
also
01 | local plrs = game:GetService "Players" |
02 |
03 | local function steppedOn 2 (part) |
04 | local plr = plrs:GetPlayerFromCharacter(part.Parent) |
05 |
06 | if plr then |
07 | if plr.UserId = = game.CreatorId then |
08 | -- your code here |
09 | end |
10 | end |
11 | end |
DataModel.CreatorId
holds a read-only int64
number. This is the UserId
of the owner.