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)
✓ ANSWER ACCEPTED
Why doesn't this sell the gun?
1 answer
✓ Accepted answer
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)
1 comment
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
please...use...playeradded. not childadded.