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: Small part of a script not working

Previous Thread :: Next Thread 
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Feb 2013 02:32 PM
local soccerfield = game.Workspace:findFirstChild("Field")
if soccerfield then
field:Destroy()
end


This part of my script is supposed to remove a model from the workspace. However, the model does not remove, and the output says that field is a nil value. (Side note: If a cloned model has anything to do with the problem, please explain why.)
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
02 Feb 2013 02:33 PM
local soccerfield = game.Workspace:findFirstChild("Field")
if soccerfield then
soccerfield:Destroy()
end

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Feb 2013 02:38 PM
That part works now, but now I can not get this script to activate another script. The script that is being affected by this script was not disabled when I checked it, but the script that is being affected did not re-run.

local gscript = game.Workspace:findFirstChild'Game script'
while wait() do
if gscript and gscript.Disabled == false then
break
else if gscript then do
gscript.Disabled = false
end
end
end--end while loop
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
02 Feb 2013 02:40 PM
Too many ends. Take 1 away

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Feb 2013 02:49 PM
Billy, I tried that. The script does not function when I take one away.
Report Abuse
Legoman654 is not online. Legoman654
Joined: 05 Jun 2008
Total Posts: 534
02 Feb 2013 02:57 PM
local gscript = game.Workspace:findFirstChild'Game script'
while wait() do
if gscript and gscript.Disabled == false then
break
else if gscript.disabled then do
gscript.Disabled = false
end
end
end--end while loop



Try that. I'm sure you need to determine whether or not it is disabled first before trying to enable it here: "else if gscript.disabled then do"
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Feb 2013 03:03 PM
Same results as my first script. Should I try a different approach? Maybe clone the script or something like that?
Report Abuse
Legoman654 is not online. Legoman654
Joined: 05 Jun 2008
Total Posts: 534
02 Feb 2013 03:08 PM
Does your first script work? As in the one where you trying to clone the brick when it was returning Field as nil?

As for the 2nd script, can you go into a bit more detail on what is not working and what you are trying to achieve? Just let me know, and I'll see if I can be further assistance
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Feb 2013 03:32 PM
For my first script: I am wanting it to loop with a while loop and to pick a random mini game. I then want it to clone that mini game model from the lighting and to put it in the workspace. Then, I want to teleport all players to that minigame and to disable the script doing all of this. (the same script)


while true do --Start while loop
wait(5)



Players = game.Players.NumPlayers
if Players <= 1 then --Checks if there are 2 or more players
local m = Instance.new("Message", game.Workspace)
m.Text = "Enough players!"
wait(5)
m.Parent = nil

minigamenumber = math.random(1, 1) --Randomly choses game

if minigamenumber == 1 then

local m = Instance.new("Message", game.Workspace)
m.Parent = game.Workspace
m.Text = "The next minigame will be"
wait(1)
m.Text = "The next minigame will be."
wait(1)
m.Text = "The next minigame will be.."
wait(1)
m.Text = "The next minigame will be..."
wait(1)
m.Text = "Soccer!"
wait(3)
m.Text = "Be the first team to score three goals to win!"
wait(5)
m.Parent = nil

game.Lighting.Field:clone().Parent = game.Workspace
game.Workspace.Field.Ball.Anchored = true

local r = Instance.new("Team", game.Teams)
local b = Instance.new("Team", game.Teams)
r.TeamColor = BrickColor.new("Bright red")
r.Name = "Red team"
b.TeamColor = BrickColor.new("Bright blue")
b.Name = "Blue team"

local plrnum = 0
for _, v in pairs(game.Players:GetPlayers()) do
plrnum = plrnum + 1
if v ~= nil then
if plrnum % 2 == 0 then
v.Teamcolor = BrickColor.new("Bright blue")
v.Neutral = false
v.Character:MoveTo(game.Workspace.Field.BlueSpawn.Position)
print 'Blue team.'
else
v.TeamColor = BrickColor.new("Bright red")
v.Neutral = false
v.Character:MoveTo(game.Workspace.Field.RedSpawn.Position)
print 'Red team.'
end
end
end

wait(3)
game.Workspace.Field.Ball.Anchored = false

game.Workspace.Field["RedGoal"].Scoreprint.Disabled = false
game.Workspace.Field["BlueGoal"].Scoreprint.Disabled = false
while wait() do
script.Disabled = true
end

else if Players >= 2 then
local m = Instance.new("Message", game.Workspace)
m.Parent = game.Workspace
m.Text = "Not enough players!"
wait(5)
m:Remove()

end


end
end
end


For my second script: I want the script to run when it is touched with the .Touched method. I want it to then add a point to the team that scored, then check if there is three points that that team scored. Then, if there is three points, I want to award that team 20 points and the losing team 10 points. After that I want to REACTIVATE the first script, and to destroy the mini game model that was cloned from the lighting.


function onTouched(part) --Function


local redsoccerscore = script.Parent:findFirstChild("RedScore")
local bluesoccerscore = script.Parent.Parent:findFirstChild("BlueGoal").BlueScore
local db = true --Variables and debounce

if part.Name == "Ball" then

if db then
db = false
redsoccerscore.Value = redsoccerscore.Value + 1
m = Instance.new("Message", game.Workspace)
m.Text = "Reds: "..redsoccerscore.Value.." Blues: "..bluesoccerscore.Value
end

if redsoccerscore.Value < 3 then
part.CFrame = game.Workspace.Field.BallSpawn.CFrame
part.Anchored = true
wait(3)
m:Destroy()
part.Anchored = false
end

if redsoccerscore.Value == 3 then
m.Text = "Reds win! Everyone gets an extra 10 points for playing."
part:Destroy()
wait(5)
m:Destroy()

local guests = game.Players:GetPlayers()
for i = 1, #guests do
if v ~= nil then
if guests.Character.TeamColor == BrickColor.new("Bright blue") then
guests.leaderstats.Points.Value = guests.leaderstats.Points.Value + 20 --20 extra points to winners
else
guests.leaderstats.Points.Value = guests.leaderstats.Points.Value + 10 --10 extra points to losers
end
end
end

local redteam = game.Teams:findFirstChild("Red team") --Remove teams
local blueteam = game.Teams:findFirstChild("Blue team")
redteam:Destroy()
blueteam:Destroy()

local gscript = game.Workspace:findFirstChild'Game script'
while wait() do
if gscript and gscript.Disabled == false then
break
else if gscript.Disabled == true then do
gscript.Disabled = false
end
end
end--end while loop

local soccerfield = game.Workspace:findFirstChild("Field")
if soccerfield then
soccerfield:Destroy()
end

db = true
end

end
end
end


script.Parent.Touched:connect(onTouched) --Connection line




Tell me if you find anything, or anything I should just tweak.
Report Abuse
Legoman654 is not online. Legoman654
Joined: 05 Jun 2008
Total Posts: 534
02 Feb 2013 04:01 PM
Sorry for the delay was reading all of your code. This should fix your issue with this script here:


local gscript = game.Workspace:findFirstChild'main'
while wait() do
if gscript and gscript.Disabled == false then
print("SCRIPT IS NOT DISABLED") -- Detects if it is not disabled. Then prints this output
break
else if gscript.Disabled == true then
gscript.Disabled = false
end
print("SCRIPT SUCCESSFULLY ENABLED") -- If it was disabled/ticked. It will untick it/enable it & print this output
end
end



Copy and paste it into your script then read my small notes. After you understand it, you can rid of the prints if you wish, or you can keep them; does not really matter
Report Abuse
Legoman654 is not online. Legoman654
Joined: 05 Jun 2008
Total Posts: 534
02 Feb 2013 04:56 PM
Leave us some feedback on whether or not my code work. I'm quite curious to know how it works in your source
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
02 Feb 2013 11:39 PM
(Sorry for not replying for a while; I had algebra and church.)

The script reactivated, but did not run. The output printed the string, but a bunch of times.
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
03 Feb 2013 12:21 AM
    local gscript = game.Workspace:findFirstChild("Game script")
    while wait() do
      if gscript and gscript.Disabled == false then
        break
      elseif gscript then do
        gscript.Disabled = false
      end
    end
Report Abuse
Legoman654 is not online. Legoman654
Joined: 05 Jun 2008
Total Posts: 534
03 Feb 2013 09:14 AM
> @TUXEDO

It's going to repeat itself because it is inside of a loop. I made it to have no errors and I put in the example for you to see, not run with it.

What is the output printing?

Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
03 Feb 2013 11:29 AM
A sample of the output:

SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
SCRIPT SUCCESSFULLY ENABLED
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
03 Feb 2013 03:53 PM
Bump.
Report Abuse
tuxedoman23 is not online. tuxedoman23
Joined: 24 Apr 2009
Total Posts: 4670
03 Feb 2013 04:51 PM
Bump.
Report Abuse
Legoman654 is not online. Legoman654
Joined: 05 Jun 2008
Total Posts: 534
04 Feb 2013 08:14 PM
Sorry for the late reply.

I wrote a new code that should work:

local gscript = game.Workspace:findFirstChild'main'
if gscript.Disabled == true
then
gscript.Disabled = false
else
print("Game Script is already Enabled")
end


This removes the constant loop since I read your full code and a constant loop is not needed. Your script will always come back to read this since it is constantly repeating to run a new game. Once both teams are killed off and spawned back to neutral, it should read that code to enable the script if it is disabled.
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