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: This script works in solo mode, but not play mode.

Previous Thread :: Next Thread 
shadowlego7 is not online. shadowlego7
Joined: 03 Mar 2007
Total Posts: 2278
07 Feb 2013 10:57 PM
p = game.Players.LocalPlayer
local Tool = script.Parentfunction onButton1Down(mouse)

if script.Parent.Disable.Value ~= true then
script.Parent.Disable.Value = true
wait (1.5)
local m = math.random(1,3)
if m == 1 then
game.Lighting["Iron Sword"]:Clone().Parent = p.Backpack
end
if m == 2 then
game.Lighting["Iron Dagger"]:Clone().Parent = p.Backpack
end
if m == 3 then
game.Lighting["Iron Spear"]:Clone().Parent = p.Backpack
end
end
script.Parent:Remove()endfunction onEquippedLocal(mouse)
if mouse == nil then
print("Mouse not found")
return
end
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

Tool.Equipped:connect(onEquippedLocal)
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
07 Feb 2013 10:59 PM
Is it in a local script?

~~Advanced Scripter
Report Abuse
shadowlego7 is not online. shadowlego7
Joined: 03 Mar 2007
Total Posts: 2278
07 Feb 2013 10:59 PM
Yes.
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Feb 2013 11:00 PM
wait() -- on the first line, don't ask questions, just do it.

local Tool = script.Parent
-- these were touching
function onButton1Down(mouse)
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
07 Feb 2013 11:01 PM
"local Tool = script.Parent
-- these were touching
function onButton1Down(mouse)"
I think that's just because he copied it weirdly, it occurred many times throughout the script.

~~Advanced Scripter
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
07 Feb 2013 11:04 PM
"if m == 1 then
game.Lighting["Iron Sword"]:Clone().Parent = p.Backpack
end
if m == 2 then
game.Lighting["Iron Dagger"]:Clone().Parent = p.Backpack
end
if m == 3 then
game.Lighting["Iron Spear"]:Clone().Parent = p.Backpack
end"

Should be:

if m == 1 then
game.Lighting["Iron Sword"]:Clone().Parent = p.Backpack
elseif m == 2 then
game.Lighting["Iron Dagger"]:Clone().Parent = p.Backpack
elseif m == 3 then
game.Lighting["Iron Spear"]:Clone().Parent = p.Backpack
else
print "Unexpected error."
end

~~Advanced Scripter
Report Abuse
RoboTestGear is not online. RoboTestGear
Joined: 28 Dec 2009
Total Posts: 3063
07 Feb 2013 11:04 PM
--[[
I coulden't really find the error, but I did clean your script up some and remove some un-needed stuff. Also, it might not work because you put it in a local script, try using a script.

]]


p = game.Players.LocalPlayer --Not sure if this will work in a tool without local
local Tool = script.Parent

function onButton1Down(mouse) --

if Tool.Disable.Value == false then --
Tool.Disable.Value = true
wait (1.5)
local m = math.random(1,3)

if m == 1 then --
game.Lighting["Iron Sword"]:Clone().Parent = p.Backpack
end ---

if m == 2 then --
game.Lighting["Iron Dagger"]:Clone().Parent = p.Backpack
end ---

if m == 3 then --
game.Lighting["Iron Spear"]:Clone().Parent = p.Backpack
end ---

end ---

script.Parent:Remove()
end --

function onEquippedLocal(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

Tool.Equipped:connect(onEquippedLocal)
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
07 Feb 2013 11:05 PM
"Also, it might not work because you put it in a local script, try using a script."
>p = game.Players.LocalPlayer

...

~~Advanced Scripter
Report Abuse
RoboTestGear is not online. RoboTestGear
Joined: 28 Dec 2009
Total Posts: 3063
07 Feb 2013 11:06 PM
Last time I checked,
game.Players.LocalPlayer requires a localized script and will only work in solo.
Report Abuse
RoboTestGear is not online. RoboTestGear
Joined: 28 Dec 2009
Total Posts: 3063
07 Feb 2013 11:07 PM
Correction for myself - Will only work in solo if the script is not localized
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Feb 2013 11:07 PM
All he needs to do is use my solution. :p
All LocalScripts need wait() at the top to work properly in online mode.
Report Abuse
shadowlego7 is not online. shadowlego7
Joined: 03 Mar 2007
Total Posts: 2278
07 Feb 2013 11:18 PM
Thanks guys. I'll try these out tomorrow, but it's really late and I got to get to sleep.
Report Abuse
shadowlego7 is not online. shadowlego7
Joined: 03 Mar 2007
Total Posts: 2278
08 Feb 2013 02:05 PM
Nope, they didn't work. I tried changing it from a LocalScript to a regular Script and edited a line, but it only works in solo, too.
-------------------

local Tool = script.Parent

function onButton1Down(mouse)
if script.Parent.Disable.Value ~= true then
script.Parent.Disable.Value = true
wait (1.5)
p = game.Players:GetPlayerFromCharacter(Tool.Parent)
local m = math.random(1,3)
if m == 1 then
game.Lighting["Iron Sword"]:Clone().Parent = p.Backpack
end
if m == 2 then
game.Lighting["Iron Dagger"]:Clone().Parent = p.Backpack
end
if m == 3 then
game.Lighting["Iron Spear"]:Clone().Parent = p.Backpack
end
end
script.Parent:Remove()
end

function onEquippedLocal(mouse)
if mouse == nil then
print("Mouse not found")
return
end
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

Tool.Equipped:connect(onEquippedLocal)
Report Abuse
shadowlego7 is not online. shadowlego7
Joined: 03 Mar 2007
Total Posts: 2278
09 Feb 2013 11:21 AM
Help? =(
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
10 Feb 2013 12:01 PM
I told you how to fix it. Put it back the way it was, and add wait() to the first line..

wait()
-- Your LocalScript code here.
Report Abuse
shadowlego7 is not online. shadowlego7
Joined: 03 Mar 2007
Total Posts: 2278
10 Feb 2013 06:11 PM
That didn't work, man.
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