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

Tycoon buy button script isnt working?

Asked by 9 years ago

I dont really get remove() but i see it on tycoons so i tried to make a buy button myself.

keeps saying WoodMine (the name of the item) is not a valid member of DataModel

any help?

script.Parent.Touched:connect(function(hit)
    local item = script.Parent.Parent.Item.Value
    if hit.Parent.Humanoid ~= nil then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.leaderstats.Money.Value > script.Parent.Parent.Price.Value or player.leaderstats.Money.Value == script.Parent.Parent.Price.Value then
            game[item].Parent = script.Parent.Parent.Parent
        end
    end
end)

2 answers

Log in to vote
0
Answered by 9 years ago
game[item].Parent = script.Parent.Parent.Parent

It's probably because the WoodMine is not in the game, if it is in Workspace then you should put:

game.Workspace[item].Parent = script.Parent.Parent

Replace Workspace depending on where it is.

Ad
Log in to vote
0
Answered by 9 years ago

The problem is that WoodMine isn't a member of DataModel, as you said. DataModelis the proper name for game. DataModel holds services only. So on line 6 of the code, you should change gameto where the model is being held, most likely in the Workspace. Some code as to what I mean:

script.Parent.Touched:connect(function(hit)
    local item = script.Parent.Parent.Item.Value
    if hit.Parent.Humanoid ~= nil then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.leaderstats.Money.Value >= script.Parent.Parent.Price.Value then -- Here I use the >= (greater than or equal to) operator.
            workspace[item].Parent = script.Parent.Parent.Parent
        end
    end
end)
0
WoodMine is not a valid member of workspace... Operation_Meme 890 — 9y

Answer this question