|
if game.Players:GetPlayers() == 1 then
script.Parent.Sound.Play()
wait(20)
script.Parent.Sound.Stop()
end
trying to get the game to recognize atleast 1 player and the sound is not playing... Is this right?
New to scripting :P :P :P |
|
smiley599Join Date: 2010-01-23 Post Count: 21869 |
if #game.Players:GetPlayers() == 1 then
script.Parent.Sound.Play()
wait(20)
script.Parent.Sound.Stop()
end |
|
smiley599Join Date: 2010-01-23 Post Count: 21869 |
or
if game.Players.NumPlayers>0 --do that |
|
|
0_0Join Date: 2010-08-15 Post Count: 1197 |
Pretty sure it's:
if game.Players.NumPlayers == 1 then
script.Sound:Play()
wait(20)
script.Sound:Stop()
end
Make sure it's called "Sound" and not "sound" and the script and Sound have the same parent. |
|
|
making sure.... one second |
|
|
None of them are working? |
|
smiley599Join Date: 2010-01-23 Post Count: 21869 |
if #game.Players:GetPlayers() >0 then
script.Parent.Sound:Play()
wait(20)
script.Parent.Sound:Stop()
end |
|
|
Alright we are making some progress now... It skips the code and teleports me (I have teleportation later in the code)
It only plays sound when I put script.Parent.Sound:Play() by itself.... |
|
danskJoin Date: 2008-12-24 Post Count: 548 |
local players = game.Players:GetPlayers() or local players = game.Players:GetChildren() -- Gets all players/children
if #players==1 then
script.Parent.Sound:Play() -- "Sound is the name of your sound"
wait(20)
script.Parent.Sound:Stop()
end
if you want a sound each time a player enters you have to use the PlayerEntered event. Look this stuff up on the wiki. |
|
0_0Join Date: 2010-08-15 Post Count: 1197 |
if game.Players.NumPlayers >= 1 then
wait()
script.Sound:Play()
wait(20)
script.Sound:Stop()
end
That should work, assuming the script and Sound both have the same parent, if I'm missing something here then do:
if game.Players.NumPlayers >= 1 then
script.Parent.Sound:Play()
wait(20)
script.Parent.Sound:Stop()
end |
|
|
No
You're doing it all wrong.
game.Players.PlayerAdded:connect(function()
local num = game.Players:GetPlayers() -- num is an array
if num[2] == nil then -- If there is no more than 1 Player in the array
script.Parent.Sound.Play()
wait(20)
script.Parent.Sound.Stop()
end
end) |
|
|
Equally, you MIGHT be able to identify number of Players by #num > 1 but that MAY not work. |
|
0_0Join Date: 2010-08-15 Post Count: 1197 |
Oh yeah a PlayerAdded event.
and lol "That should work, assuming the script and Sound both have the same parent"
If you used my script you would have to actually put the Sound inside the script, I'm so tired I've been trying to do something for 4 hours and it's not working and SH isn't helping xD |
|
|
sadly none of this is working..... ima check wiki |
|
|
So now I know I have to do an event that makes the game count the players....
do I put something like this?
game.Players.PlayerAdded:connect(function(player)
code texty stuff here. |
|
|
Where's the "Sound" located exactly?. |
|
LuaSlayerJoin Date: 2014-07-09 Post Count: 38 |
I am new to ROBLOX
I feel dizzy from all this scripting xD |
|
|
Sound is located in the workspace and so is the script. I did script.Parent.Sound:Play() |
|
|
ash877Join Date: 2008-02-18 Post Count: 5142 |
can you post the entire script? |
|
|
Whole Script:
Spot1= Vector3.new(10,10,10)
Spot2= Vector3.new(30,30,30)
Spot3= Vector3.new(20,20,20)
game.Players.PlayerAdded:connect(function()
local num = game.Players:GetPlayers() -- num is an array
if num[2] == nil then -- If there is no more than 1 Player in the array
script.Parent.Sound.Play()
wait(20)
script.Parent.Sound.Stop()
end
end)
wait()
for i,v in pairs(game.Players:GetPlayers()) do
if v.TeamColor == BrickColor.new("Bright red") then
v.Character.Torso.CFrame = CFrame.new(Spot1)
elseif v.TeamColor == BrickColor.new("White") then
v.Character.Torso.CFrame = CFrame.new(Spot2)
elseif v.TeamColor == BrickColor.new("Dark Green") then
v.Character.Torso.CFrame = CFrame.new(Spot3)
end
end
function GameGuns()
wait(3)
end
wait()
function GameEnd()
wait(3)
end
wait() |
|
|
smiley599Join Date: 2010-01-23 Post Count: 21869 |
It's :Play not .Play i think |
|
|
Yay its solved! I was stoopid! Thanks all for who helped me! |
|