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

Why won't my shop script work?

Asked by 9 years ago

I have a localscript that is supposed to give a player a sword if they click an ImageButton, but it won't work. Does anyone know why and can you help me fix it?

01local ItemName = "Orc Blade"
02local Cost = 100
03local Currency = "Coins"
04 
05MinusMoney = true
06SaveOnDeath = true
07 
08local player = game.Players.LocalPlayer
09local ToolClone = game.Lighting:findFirstChild(ItemName):clone()
10 
11script.Parent.MouseButton1Click:connect(function(player)
12    if player.leaderstats:findFirstChild(Currency) ~= nil then
13        local cash = player.leaderstats:findFirstChild(Currency)
14        if cash.Value >= Cost and player.Backpack:findFirstChild(ItemName) == nil then
15            local ToolClone2 = ToolClone:clone()
View all 26 lines...

1 answer

Log in to vote
1
Answered by
Voltoxus 248 Moderation Voter
9 years ago

Its pretty weird, but what I assume is happening which doesn't make any sense is local player isn't loading even thought you pre-declared it. To fix this I moved the player declaration to inside the function.

01local ItemName = "Orc Blade"
02local Cost = 100
03local Currency = "Coins"
04 
05MinusMoney = true
06SaveOnDeath = true
07 
08local ToolClone = game.Lighting:findFirstChild(ItemName):clone()
09 
10script.Parent.MouseButton1Click:connect(function(player)
11    local player = game.Players.LocalPlayer
12    if player.leaderstats:findFirstChild(Currency) ~= nil then
13        local cash = player.leaderstats:findFirstChild(Currency)
14        if cash.Value >= Cost and player.Backpack:findFirstChild(ItemName) == nil then
15            local ToolClone2 = ToolClone:clone()
View all 26 lines...
Ad

Answer this question