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

FE Shop only gives the item once then breaks?

Asked by 6 years ago
Edited 6 years ago

this is a localscript that fires a remote that charges the player $300 for a baseball bat however it only works once then it doesn't work the second time and comes up with an error.Also my guy had enough money

script.Parent.MouseButton1Click:Connect(function()
    local plr=game.Players.LocalPlayer
    local cash=plr.Data.Wallet
    if cash.Value>=300 then 
        local event=game.ReplicatedStorage.backpack
        event:FireServer("Baseball Bat",300)
        script.Parent.Parent.Visible=false
    end
end)

The error is on the remote script's line 8



game.ReplicatedStorage.backpack.OnServerEvent:connect(function(plr,Message,cost) local pack=game.ServerStorage.Tools:FindFirstChild(Message) local cash=plr.Data.Wallet cash.Value=cash.Value-cost pack:Clone() pack.Parent=plr.Backpack end)

error: https://gyazo.com/8da86a9c465e60591667ff85c24109a6

2 answers

Log in to vote
0
Answered by 6 years ago
game.ReplicatedStorage.backpack.OnServerEvent:connect(function(plr,Message,cost)

    if not Message then
        print("Invalid Item")
        return
    end

    local serverStorage = game:GetService("ServerStorage")
    local pack = serverStorage.Tools:WaitForChild(Message)
    local cash = plr.Data.Wallet

    cash.Value = cash.Value - cost
    pack:Clone()
    pack.Parent = plr.Backpack
end)

Try this maybe it will work for you.

0
Now its saying "Infinite yield possible on 'ServerStorage.Tools:WaitForChild("Chicken Leg")'" shankable 9 — 6y
0
Well hopefully Chicken Leg is actually there. But you can add an extra parameter for a yeild counter and if it never finds the item within a certain amount of time just cancel the purchase. Ex: local pack = serverStorage.Tools:WaitForChild(Message, 10) if not pack then print("Couldn't locate item. Canceling purchase.") return end) Impacthills 223 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

When you go to clone the item, dont make the variable and then clone. I believe you are actually just moving the item from replicated storage to the players Backpack. do this instead

game.ReplicatedStorage.backpack.OnServerEvent:connect(function(plr,Message,cost)

    local pack=game.ServerStorage.Tools:FindFirstChild(Message):Clone() -- add clone here
    local cash=plr.Data.Wallet
    cash.Value=cash.Value-cost
    pack.Parent=plr.Backpack
end)

Answer this question