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

Previous Thread :: Next Thread 
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
11 Nov 2013 09:10 PM
Ok so I have a script and there is a issue with it and it's one single line. I'll add ------ around the area!
OUTPUT:
attempt to call method 'Changed' (a nil value)
SCRIPT:
function CheckTrainer(team)
for _,plrs in pairs(game.Players:GetPlayers()) do
if plrs.TeamColor == game.Teams.Trainers.TeamColor then return true
end
return false
end
end

function ChangeSim(name)
for i, v in ipairs(game.Lighting.Sims:children()) do
if v.Name:lower() == name:lower() then
local oldsim = game.Workspace.CurrSim:children()
for a = 1, #oldsim do
oldsim[a]:Destroy()
end
local cl = v:Clone()
cl.Parent = game.Workspace.CurrSim
cl:MakeJoints()
end
end
end
--------------------------------------------------------------------
plrsv = game.Players:GetPlayers()
plrsv:Changed(TeamColor):connect(function(plr)
--------------------------------------------------------------------
if CheckTrainer(team) then
repeat wait() until plr:findFirstChild("PlayerGui") script.TrainerGui:Clone().Parent = plr.PlayerGui
plr.Chatted:connect(function(msg)
if msg:lower() == "clear sim" then
ChangeSim("NoSim")
elseif string.sub(msg:lower(),1,4) == "run " then
ChangeSim(string.sub(msg:lower(),5))
elseif msg:lower() == "end sim" then
game.Workspace.Base.SimDoor.CanCollide = true
game.Workspace.Base.SimDoor.Transparency = 0.5
game.Workspace.Base.a1.CanCollide = true
game.Workspace.Base.a2.CanCollide = true
game.Workspace.Base.a3.CanCollide = true
game.Workspace.Base.a4.CanCollide = true
game.Workspace.Base.a1.Transparency = 0.5
game.Workspace.Base.a2.Transparency = 0.5
game.Workspace.Base.a3.Transparency = 0.5
game.Workspace.Base.a4.Transparency = 0.5
for i, plr in ipairs(game.Players:children()) do
if plr and plr.Character and plr.Character:findFirstChild("Torso") then
if plr.Character.Torso:findFirstChild("Contour") then game:service("Debris"):AddItem(plr.Character.Torso:findFirstChild("Contour"), 0) end
for w, wepz in pairs(plr.Character:children()) do if wepz:IsA("Tool") then game:service("Debris"):AddItem(wepz, 0) end end
for w, wepz in pairs(plr.Backpack:children()) do if wepz:IsA("Tool") then game:service("Debris"):AddItem(wepz, 0) end end
local spawns = game.Workspace.SimSpawns:children()
if #spawns ~= 0 then
local spn = spawns[math.random(1,#spawns)]
if spn and plr.Character:findFirstChild("Torso") then
plr.Character.Torso.CFrame = (spn.CFrame + Vector3.new(0,3,0))
end
end
end
end
elseif msg:lower() == "open sim" then
game.Workspace.Base.SimDoor.CanCollide = false
game.Workspace.Base.SimDoor.Transparency = 1
elseif msg:lower() == "close sim" then
game.Workspace.Base.SimDoor.CanCollide = true
game.Workspace.Base.SimDoor.Transparency = 0.5
elseif msg:lower() == "open arena" then
game.Workspace.Base.a1.CanCollide = false
game.Workspace.Base.a2.CanCollide = false
game.Workspace.Base.a3.CanCollide = false
game.Workspace.Base.a4.CanCollide = false
game.Workspace.Base.a1.Transparency = 1
game.Workspace.Base.a2.Transparency = 1
game.Workspace.Base.a3.Transparency = 1
game.Workspace.Base.a4.Transparency = 1
elseif msg:lower() == "close arena" then
game.Workspace.Base.a1.CanCollide = true
game.Workspace.Base.a2.CanCollide = true
game.Workspace.Base.a3.CanCollide = true
game.Workspace.Base.a4.CanCollide = true
game.Workspace.Base.a1.Transparency = 0.5
game.Workspace.Base.a2.Transparency = 0.5
game.Workspace.Base.a3.Transparency = 0.5
game.Workspace.Base.a4.Transparency = 0.5
elseif msg:lower() == "open spawns" then
game.Workspace.Base.s1.CanCollide = false
game.Workspace.Base.s2.CanCollide = false
game.Workspace.Base.s1.Transparency = 1
game.Workspace.Base.s2.Transparency = 1
elseif msg:lower() == "close spawns" then
game.Workspace.Base.s1.CanCollide = true
game.Workspace.Base.s2.CanCollide = true
game.Workspace.Base.s1.Transparency = 0.5
game.Workspace.Base.s2.Transparency = 0.5
elseif msg:lower():find("begin!") then
if game.Workspace.CurrSim:findFirstChild("SimBegin", true) then
game.Workspace.CurrSim:findFirstChild("SimBegin", true):Destroy()
game.Workspace.Base.SimDoor.CanCollide = true
game.Workspace.Base.SimDoor.Transparency = 0.5
end
elseif msg:lower():find("notalk") then
for _,plrss in pairs(game.Players:GetPlayers()) do
if plrss.TeamColor ~= game.Teams.Trainers.TeamColor then
plrss.NoTalk.Value = 3
end
end
elseif msg:lower():find("talk") then
for _,plrsb in pairs(game.Players:GetPlayers()) do
plrsb.NoTalk.Value = 5
end
if game.Workspace.CurrSim:findFirstChild("SimBeginOpen", true) then
game.Workspace.CurrSim:findFirstChild("SimBeginOpen", true):Destroy()
end
end
end)
end
end)
Report Abuse
MantarayJack is not online. MantarayJack
Joined: 22 Dec 2012
Total Posts: 183
11 Nov 2013 09:16 PM
Change this line

plrsv:Changed(TeamColor):connect(function(plr)

To this

plrsv.PlayerAdded:connect(function(plr)
plr.Changed:connect(function(property)
if property != "TeamColor" then return end



And this last line

end)

To this

end)
end)
Report Abuse
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
11 Nov 2013 09:21 PM
-- (*STILL DON'T WORK*)
-Output: 22:20:04.889 - Workspace.Commands:24: attempt to index field 'PlayerAdded' (a nil value)
-Script:
function CheckTrainer(team)
for _,plrs in pairs(game.Players:GetPlayers()) do
if plrs.TeamColor == game.Teams.Trainers.TeamColor then return true
end
return false
end
end

function ChangeSim(name)
for i, v in ipairs(game.Lighting.Sims:children()) do
if v.Name:lower() == name:lower() then
local oldsim = game.Workspace.CurrSim:children()
for a = 1, #oldsim do
oldsim[a]:Destroy()
end
local cl = v:Clone()
cl.Parent = game.Workspace.CurrSim
cl:MakeJoints()
end
end
end
plrsv = game.Players:GetPlayers()
plrsv.PlayerAdded:connect(function(plr)
plr.Changed:connect(function(property)
if property == "TeamColor" then return end
if CheckTrainer(team) then
repeat wait() until plr:findFirstChild("PlayerGui") script.TrainerGui:Clone().Parent = plr.PlayerGui
plr.Chatted:connect(function(msg)
if msg:lower() == "clear sim" then
ChangeSim("NoSim")
elseif string.sub(msg:lower(),1,4) == "run " then
ChangeSim(string.sub(msg:lower(),5))
elseif msg:lower() == "end sim" then
game.Workspace.Base.SimDoor.CanCollide = true
game.Workspace.Base.SimDoor.Transparency = 0.5
game.Workspace.Base.a1.CanCollide = true
game.Workspace.Base.a2.CanCollide = true
game.Workspace.Base.a3.CanCollide = true
game.Workspace.Base.a4.CanCollide = true
game.Workspace.Base.a1.Transparency = 0.5
game.Workspace.Base.a2.Transparency = 0.5
game.Workspace.Base.a3.Transparency = 0.5
game.Workspace.Base.a4.Transparency = 0.5
for i, plr in ipairs(game.Players:children()) do
if plr and plr.Character and plr.Character:findFirstChild("Torso") then
if plr.Character.Torso:findFirstChild("Contour") then game:service("Debris"):AddItem(plr.Character.Torso:findFirstChild("Contour"), 0) end
for w, wepz in pairs(plr.Character:children()) do if wepz:IsA("Tool") then game:service("Debris"):AddItem(wepz, 0) end end
for w, wepz in pairs(plr.Backpack:children()) do if wepz:IsA("Tool") then game:service("Debris"):AddItem(wepz, 0) end end
local spawns = game.Workspace.SimSpawns:children()
if #spawns ~= 0 then
local spn = spawns[math.random(1,#spawns)]
if spn and plr.Character:findFirstChild("Torso") then
plr.Character.Torso.CFrame = (spn.CFrame + Vector3.new(0,3,0))
end
end
end
end
elseif msg:lower() == "open sim" then
game.Workspace.Base.SimDoor.CanCollide = false
game.Workspace.Base.SimDoor.Transparency = 1
elseif msg:lower() == "close sim" then
game.Workspace.Base.SimDoor.CanCollide = true
game.Workspace.Base.SimDoor.Transparency = 0.5
elseif msg:lower() == "open arena" then
game.Workspace.Base.a1.CanCollide = false
game.Workspace.Base.a2.CanCollide = false
game.Workspace.Base.a3.CanCollide = false
game.Workspace.Base.a4.CanCollide = false
game.Workspace.Base.a1.Transparency = 1
game.Workspace.Base.a2.Transparency = 1
game.Workspace.Base.a3.Transparency = 1
game.Workspace.Base.a4.Transparency = 1
elseif msg:lower() == "close arena" then
game.Workspace.Base.a1.CanCollide = true
game.Workspace.Base.a2.CanCollide = true
game.Workspace.Base.a3.CanCollide = true
game.Workspace.Base.a4.CanCollide = true
game.Workspace.Base.a1.Transparency = 0.5
game.Workspace.Base.a2.Transparency = 0.5
game.Workspace.Base.a3.Transparency = 0.5
game.Workspace.Base.a4.Transparency = 0.5
elseif msg:lower() == "open spawns" then
game.Workspace.Base.s1.CanCollide = false
game.Workspace.Base.s2.CanCollide = false
game.Workspace.Base.s1.Transparency = 1
game.Workspace.Base.s2.Transparency = 1
elseif msg:lower() == "close spawns" then
game.Workspace.Base.s1.CanCollide = true
game.Workspace.Base.s2.CanCollide = true
game.Workspace.Base.s1.Transparency = 0.5
game.Workspace.Base.s2.Transparency = 0.5
elseif msg:lower():find("begin!") then
if game.Workspace.CurrSim:findFirstChild("SimBegin", true) then
game.Workspace.CurrSim:findFirstChild("SimBegin", true):Destroy()
game.Workspace.Base.SimDoor.CanCollide = true
game.Workspace.Base.SimDoor.Transparency = 0.5
end
elseif msg:lower():find("notalk") then
for _,plrss in pairs(game.Players:GetPlayers()) do
if plrss.TeamColor ~= game.Teams.Trainers.TeamColor then
plrss.NoTalk.Value = 3
end
end
elseif msg:lower():find("talk") then
for _,plrsb in pairs(game.Players:GetPlayers()) do
plrsb.NoTalk.Value = 5
end
if game.Workspace.CurrSim:findFirstChild("SimBeginOpen", true) then
game.Workspace.CurrSim:findFirstChild("SimBeginOpen", true):Destroy()
end
end
end)
end
end)
end)
Report Abuse
MantarayJack is not online. MantarayJack
Joined: 22 Dec 2012
Total Posts: 183
11 Nov 2013 09:26 PM
Change this line

plrsv = game.Players:GetPlayers()

To this

plrsv = game:GetService("Players")


I thought it already was defined as such, since it seemed to me the variable was named for 'player service'.
Report Abuse
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
11 Nov 2013 09:27 PM
Would you have a way to put this on a loop? Basically I want to not when character add but keep it on a loop so when they team change they can still use the chat commands.
Report Abuse
MantarayJack is not online. MantarayJack
Joined: 22 Dec 2012
Total Posts: 183
11 Nov 2013 09:31 PM
Change this line

if property == "TeamColor" then return end

To this

if property ~= "TeamColor" then return end

I made a typo in my code, but this line should work properly.


The code within this structure

plrsv = game.Players:GetPlayers()
plrsv.PlayerAdded:connect(function(plr)
plr.Changed:connect(function(property)
if property == "TeamColor" then return end
-- Here
end)
end)

Should run for each player that joins, whenever the player's 'TeamColor' property is changed (the player is assigned to a different team).
Report Abuse
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
11 Nov 2013 09:31 PM
We have another issue, the GUI that is supposed to be clone keeps cloning and it spams your screen. Would it be possible to add a simple if GUI == nil then clone()?
Report Abuse
MantarayJack is not online. MantarayJack
Joined: 22 Dec 2012
Total Posts: 183
11 Nov 2013 09:36 PM
Change this line

repeat wait() until plr:findFirstChild("PlayerGui") script.TrainerGui:Clone().Parent = plr.PlayerGui

To this

local playerGui = plr:WaitForChild("PlayerGui")
if not playerGui:FindFirstChild("TrainerGui") then
script.TrainerGui:Clone().Parent = playerGui
end
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