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

Removing certain tools with dailog shop?

Asked by 8 years ago

Below is the script for a dailog shop. It is very similar to that found in roblox wiki here.

local dialog = script.Parent
dialog.DialogChoiceSelected:connect(function(player, choice)
    local stats = player:FindFirstChild('leaderstats')
    if not stats then return end

    local gold = stats:FindFirstChild('Gold')
    if not gold then return end

    if choice == script.Parent.DialogChoice.ChoiceA then
        if gold.Value >= 500 then
            game.ReplicatedStorage.AK-47:Clone().Parent = player.Backpack
            gold.Value = gold.Value - 500 
        end

While this script works, I want to make it so if you buy the AK, it replaces a certain weapon in your backpack (example, if you have a healthkit and a assault rifle in your backpack, buying the AK replaces the assault rifle ONLY).

Thanks!

0
Your wording throws me off a bit. Try making an example script? Shawnyg 4330 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

It's just another if statement

If this exists, do that. Except in this case, 'that' is destroying 'this'.

local dialog = script.Parent
dialog.DialogChoiceSelected:connect(function(player, choice)
    local stats = player:FindFirstChild('leaderstats')
    if not stats then return end

    local gold = stats:FindFirstChild('Gold')
    if not gold then return end

    if choice == script.Parent.DialogChoice.ChoiceA then
        if gold.Value >= 500 then
            game.ReplicatedStorage.AK-47:Clone().Parent = player.Backpack
            gold.Value = gold.Value - 500 
        if player.Backpack:FindFirstChild("M4A4") then -- Assault Rifle.
        player.Backpack.M4A4:Destroy();
        end
        end
-- I'll just ignore the amount of missing ends and assume the script snippet is truncated.
Ad

Answer this question