generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Chatted script

Previous Thread :: Next Thread 
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
13 Aug 2012 04:40 PM
I am trying to make a script that plays a sound when someone says Yes Sir or Sir Yes Sir. But it won't work. And output says NOTHING. It seems like the code alreay breaks at the PlayerAdded line.

function GiveSoundToCharacterAndPlayIt(Sound, Character)
if Sound and Character then
print("Secured that it is a character and that the sound is a Sound >:O")
local NewSound = Sound:Clone()
NewSound.Parent = Character.Head
NewSound:Play()
wait(3)
NewSound:Destroy()
end
end

function Chatted(Msg, Speaker)
print("Chatted")
local Msg = Msg:lower()
if string.find(Msg, "yes") == 1 and string.find(Msg, "sir") == 5 then
GiveSoundToCharacterAndPlayIt(script.YesSir, Speaker.Character)
end
if string.find(Msg, "sir") == 1 and string.find(Msg, "yes") == 5 and string.sub(Msg, 9, 11) == "sir" then
GiveSoundToCharacterAndPlayIt(script.YesSir, Speaker.Character)
end
end

game.Players.PlayerAdded:connect(function(P)
P.Chatted:connect(function(Msg) Chatted(Msg, P) end)
end)
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
13 Aug 2012 04:42 PM
Myself, I don't see anything that should stop it from printing anything.
Are you certain this code is running before any players join?
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
13 Aug 2012 04:43 PM
Not sure. But other scripts I've wrote in the same way works.
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
13 Aug 2012 04:48 PM
I need help with it. D:
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
13 Aug 2012 04:57 PM
Nobody? D:
Report Abuse
EpikYummeh is online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
13 Aug 2012 05:02 PM
Why not just check the message against a value instead of using string.find?

Example:
if (msg == "sir yes sir" or msg == "yes sir") then
-- ...
end
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
13 Aug 2012 05:06 PM
I use string.find so it doesn't matter if they end the message with "!" or ".". But the most strange is that it doesn't even runs the code when the player chatts.
Report Abuse
ShoeBox4 is not online. ShoeBox4
Joined: 06 Apr 2011
Total Posts: 890
13 Aug 2012 05:08 PM
if msg:lower():sub(1, 7) == "yes sir" or msg:lower():sub(1, 11) == "sir yes sir" then
--Do stuff
end
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
13 Aug 2012 05:14 PM
Why didn't I think of that... Oh well. I'll try it.
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
13 Aug 2012 05:18 PM
It seems like the script breaks before the PlayerAdded line. :/
Report Abuse
swatteam773 is not online. swatteam773
Joined: 01 May 2009
Total Posts: 321
13 Aug 2012 05:19 PM
Didnt work..
Report Abuse
Ozzypig is not online. Ozzypig
Joined: 27 Mar 2008
Total Posts: 4906
13 Aug 2012 05:45 PM
string.find() returns more than one argument, maybe that's what's causing it.
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
13 Aug 2012 05:53 PM
"string.find() returns more than one argument, maybe that's what's causing it."

No, because Lua will automatically collect the rest when in a comparison statement. It also fixates any call to the output the isn't the only or last to one value as well.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
13 Aug 2012 05:56 PM
The reason it didn't work was probably because replication was slow on the server.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
13 Aug 2012 06:22 PM
local _G,_VERSION,assert,collectgarbage,dofile,error,getfenv,getmetatable,ipairs,load,loadfile,loadstring,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,coroutine,math,string,table,game,Game,workspace,Workspace,delay,Delay,LoadLibrary,printidentity,Spawn,tick,time,version,Version,Wait,wait,PluginManager,crash__,LoadRobloxLibrary,settings,Stats,stats,UserSettings,Enum,Color3,BrickColor,Vector2,Vector3,Vector3int16,CFrame,UDim,UDim2,Ray,Axes,Faces,Instance,Region3,Region3int16=_G,_VERSION,assert,collectgarbage,dofile,error,getfenv,getmetatable,ipairs,load,loadfile,loadstring,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,coroutine,math,string,table,game,Game,workspace,Workspace,delay,Delay,LoadLibrary,printidentity,Spawn,tick,time,version,Version,Wait,wait,PluginManager,crash__,LoadRobloxLibrary,settings,Stats,stats,UserSettings,Enum,Color3,BrickColor,Vector2,Vector3,Vector3int16,CFrame,UDim,UDim2,Ray,Axes,Faces,Instance,Region3,Region3int16
math.randomseed(tick())

local function WaitForChild(Parent, Name)
local Item = Parent:FindFirstChild(Name)
if not Item then
repeat wait(0) print("Waiting for "..Name) Item = Parent:FindFirstChild(Name) until Item
end
return Item;
end


local Sound = WaitForChild(script, "YesSir")
local Players = Game:GetService('Players')




local function GiveSoundToCharacterAndPlayIt(Sound, Character)
if Sound and Character and Character:FindFirstChild("Head") and Character.Head:IsA("BasePart") then
print("Secured that it is a character and that the sound is a Sound >:O.")
local NewSound = Sound:Clone()
NewSound.Parent = Character.Head
NewSound:Play()
wait(3)
NewSound:Destroy()
end
end

local function Chatted(Message, Speaker)
print("Chatted")
if Message:lower():sub(1, 7) == "yes sir" or Message:lower():sub(1, 11) == "sir yes sir" or Message:lower():sub(1, 12) == "sir, yes sir" then
GiveSoundToCharacterAndPlayIt(script.YesSir, Speaker.Character)
end
end

for _, Player in pairs(Players:GetPlayers()) do
Player.Chatted:connect(function(Message)
Chatted(Message, Player)
end)
end

Players.PlayerAdded:connect(function(Player)
Player.Chatted:connect(function(Message)
Chatted(Message, Player)
end)
end)



------------------------------
On 8/13/2012 at 5:35 PM FoxSpookyMulder wrote:

function GiveSoundToCharacterAndPlayIt(Sound, Character)
if Sound and Character then
print("Secured that it is a character and that the sound is a Sound >:O")
local NewSound = Sound:Clone()
NewSound.Parent = Character.Head
NewSound:Play()
wait(3)
NewSound:Destroy()
end
end

function Chatted(Msg, Speaker)
print("Chatted")
if Msg:lower():sub(1, 7) == "yes sir" or Msg:lower():sub(1, 11) == "sir yes sir" then
GiveSoundToCharacterAndPlayIt(script.YesSir, Speaker.Character)
end
end

game.Players.PlayerAdded:connect(function(P)
P.Chatted:connect(function(Msg) Chatted(Msg, P) end)
end)
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
13 Aug 2012 06:51 PM
"The reason it didn't work was probably because replication was slow on the server."

You're insane.
Report Abuse
swatteam773 is not online. swatteam773
Joined: 01 May 2009
Total Posts: 321
13 Aug 2012 07:26 PM
Quenty, that still doesnt work.
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
14 Aug 2012 07:32 AM
It works in Play Solo but not in online. D:
Report Abuse
romaster512 is not online. romaster512
Joined: 13 Mar 2009
Total Posts: 1250
14 Aug 2012 07:35 AM
It's not in a LocalScript, is it?
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
14 Aug 2012 09:40 AM
Nope.
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
14 Aug 2012 09:57 AM
Just do this.

function find(w, s)
for i = 1, s:len() do
if msg:sub(i, (i - 1) + w:len()):lower() == w:lower() then
retrun true
end
end
return false
end

function GiveSoundToCharacterAndPlayIt(Sound, Character)
if Sound and Character then
print("Secured that it is a character and that the sound is a Sound >:O")
local NewSound = Sound:Clone()
NewSound.Parent = Character.Head
NewSound:Play()
wait(3)
NewSound:Destroy()
end
end

function Chatted(Msg, Speaker)
if find("yes sir", msg:lower()) == true then
GiveSoundToCharacterAndPlayIt(script.YesSir, Speaker.Character)
end
end

game.Players.PlayerAdded:connect(function(P)
P.Chatted:connect(function(Msg) Chatted(Msg, P) end)
end)
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
14 Aug 2012 10:57 AM
18 yours didn't work.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
14 Aug 2012 11:00 AM
game.Players.ChildAdded:connect(function (newPlayer)
newPlayer.Chatted:connect(function (msg)
if (msg:lower():gsub(" ", ""):find("yessir")) then
if (not newPlayer.Character) then print("No character"); return; end
local soundName = "YesSir";
if (not script:findFirstChild(soundName)) then print("No sound"); return; end
local newSound = script[soundName]:Clone();
newSound.Parent = newPlayer.Character;
newSound:Play();
wait(3);
newSound:Destroy();
end
end);
end);
Report Abuse
FoxSpookyMulder is not online. FoxSpookyMulder
Joined: 28 Aug 2011
Total Posts: 58
14 Aug 2012 11:20 AM
Didn't work. D:
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
14 Aug 2012 11:25 AM
1) Output?
2) Did you upload the sound from your computer or is it an official roblox-made sound?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image