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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
2
Answered by
Elixcore 1337 Moderation Voter
5 years ago
Edited 5 years ago

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

0
correct User#19524 175 — 5y
0
yep CjayPlyz 643 — 5y
0
Sorry, I accidentally posted what I was originally using. I've fixed it to call upon the variable used in the starting script CoosBuckett 10 — 5y
0
see if this works Elixcore 1337 — 5y
View all comments (5 more)
0
also on the new script you posted owner is not used correctly, you'd have to use game.Players[owner.Value] Elixcore 1337 — 5y
0
Thanks! This fixed my problem CoosBuckett 10 — 5y
0
Line 3 is unnecessary. Obviously it has a parent. Else the code couldn’t run since the part didn’t exist. User#19524 175 — 5y
0
Yeah I realized that, my bad. Elixcore 1337 — 5y
0
deleted Elixcore 1337 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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.

0
What is the CreatorId? CjayPlyz 643 — 5y
0
CreatorId is the UserId of the creator of the place. User#19524 175 — 5y
0
It’s a property of game User#19524 175 — 5y

Answer this question