|
| 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 |
|
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 |
|
|
| 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 |
|