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
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
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.