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

Why doesn't this sell the gun?

Asked by
Akozta 40
8 years ago
function onChatted(msg, recipient, speaker)   

    local source = speaker.Name

    msg = string.lower(msg) 

    if string.sub(msg,1,5) == "Sell " then 

        if workspace:findFirstChild(speaker.Name) == nil then return end
        if workspace:findFirstChild(speaker.Name).Humanoid.Health <= 0 then return end

        if string.sub(msg,6) == "Gun" then --Change this for every gun name.
            if speaker.Backpack:findFirstChild("Gun") ~= nil then
                speaker.Backpack.Gun:destroy()
                speaker.leaderstats.cash.Value = speaker.leaderstats.cash.Value+50 
            end
        end
        end
        end
function onPlayerEntered(newPlayer) 
    newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end  


game.Players.PlayerAdded:connect(onPlayerEntered)
2
please...use...playeradded. not childadded. unmiss 337 — 8y

1 answer

Log in to vote
1
Answered by
xAtom_ik 574 Moderation Voter
8 years ago

The reason why is because you made it detect it lowercase so this is how it would be if you wanted it lowercase:

function onChatted(msg, recipient, speaker)   

    local source = speaker.Name

    msg = string.lower(msg) 

    if string.sub(msg,1,5) == "sell " then 

        if workspace:findFirstChild(speaker.Name) == nil then return end
        if workspace:findFirstChild(speaker.Name).Humanoid.Health <= 0 then return end

        if string.sub(msg,6) == "gun" then --Change this for every gun name.
            if speaker.Backpack:findFirstChild("Gun") ~= nil then
                speaker.Backpack.Gun:destroy()
                speaker.leaderstats.cash.Value = speaker.leaderstats.cash.Value+50 
            end
        end
        end
        end
function onPlayerEntered(newPlayer) 
    newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end  


game.Players.PlayerAdded:connect(onPlayerEntered)

0
Oh man, I initially had it lower cased, but I let my friend add an "end", and he didn't tell me he capitalized.....Thanks so much dude, I was wondering why this wasn't working. Akozta 40 — 8y
Ad

Answer this question