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

Dialog Shop Broken, please help?

Asked by 9 years ago

Okay, so when I play and try to buy the gun it says: 'player is not a valid member of Players' when in this code:

workspace.Joe.Head.Dialog.DialogChoiceSelected:connect(function(player,choice)
       if choice.Name == "Silencer" then
        for _,Player in pairs(game.Players.player.Name) do
        if Player:FindFirstChild("leaderstats") then
            if Player.leaderstats.Money.Value >= 130 and player.Backpack:FindFirstChild("M4A4") then
            player.Backpack.M4A4:Destroy()  
            Player.leaderstats.Money.Value = Player.leaderstats.Money.Value -130
            game.Lighting.SilencedM4A4:Clone().Parent = player.Backpack
            else
                if player.Backpack:FindFirstChild("M4A4") == nil then
                    choice.ResponseDialog = "Sorry, you don't have a glock"
                    end
                end 
        else
            if Player.leaderstats.Money.Value < 130 then
                choice.ResponseDialog = "Sorry, you don't have enough money!"
end
        end
    end
    end
end)

It gets the player in function when they click the dialog! Please help!

1 answer

Log in to vote
0
Answered by 9 years ago

The problem is, player is an object. for _,players need a TABLE, like if you get children or players. A Table could be a whole list of objects. In this case, we are trying to find the player(which is already a variable.) Just replace all the capital, "P"s in "Player" and get rid of the for loop.

workspace.Joe.Head.Dialog.DialogChoiceSelected:connect(function(player,choice)
       if choice.Name == "Silencer" then --removed for loop.
        if player:FindFirstChild("leaderstats") then --all "Player" are now "player" since player was referenced on the first line of the code.
            if player.leaderstats.Money.Value >= 130 and player.Backpack:FindFirstChild("M4A4") then
            player.Backpack.M4A4:Destroy()  
            player.leaderstats.Money.Value = player.leaderstats.Money.Value -130
            game.Lighting.SilencedM4A4:Clone().Parent = player.Backpack
            else
                if player.Backpack:FindFirstChild("M4A4") == nil then
                    choice.ResponseDialog = "Sorry, you don't have a glock"
                    end
                end 
        else
            if player.leaderstats.Money.Value < 130 then
                choice.ResponseDialog = "Sorry, you don't have enough money!"
end
    end
    end
end)

Hope it helps!

0
Thank you so much!!!! LostInCode 30 — 9y
Ad

Answer this question