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 » Scripters
Home Search
 

Re: I need help fixing this function

Previous Thread :: Next Thread 
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
01 Mar 2015 02:47 PM
This is within a local script in the startergui, what it's supposed to do is any model named GoldModel will dissappear when touched, also it will add a point. The issue is when I start the game, the gold doesnt go into lighting when touched, nor does it give a point, however GoldDetector and GoldBase do turn transparent. Any help is appreciated!


c=game.Workspace:GetChildren()
for _,v in pairs(c) do
if v.Name=="GoldModel" then
gm=v
g=gm.Gold
gd=gm.GoldDetector
gb=gm.GoldBase
gb.Transparency=1
gd.Transparency=1
end
end

function onTouched(limb)
local character = limb.Parent
local player = game.Players:GetPlayerFromCharacter(character)
player.leaderstats.Gold.Value=player.leaderstats.Gold.Value+1
gm.Parent=game.Lighting
end

gd.Touched:connect(onTouched)
Report Abuse
XtremeTemper is not online. XtremeTemper
Joined: 02 Mar 2012
Total Posts: 1774
01 Mar 2015 02:51 PM
c=game.Workspace:GetChildren()
gd = nil

for _,v in pairs(c) do
if v.Name=="GoldModel" then
gm=v
g=gm.Gold
gd=gm.GoldDetector
gb=gm.GoldBase
gb.Transparency=1
gd.Transparency=1
end
end

function onTouched(limb)
if limb.Parent:findFirstChild("Humanoid") then
local character = limb.Parent
local player = game.Players:GetPlayerFromCharacter(character)
player.leaderstats.Gold.Value=player.leaderstats.Gold.Value+1
gm.Parent=game.Lighting
end
end

gd.Touched:connect(onTouched)
Report Abuse
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
01 Mar 2015 02:56 PM
muy gracias :D
Report Abuse
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
01 Mar 2015 02:58 PM
Wait, nvm...
I forgot to mention there are multiple GoldModels, I want it to pick up all of them, but it only picks up the first one on the list.
Report Abuse
XtremeTemper is not online. XtremeTemper
Joined: 02 Mar 2012
Total Posts: 1774
01 Mar 2015 03:01 PM
So you want to use one script and use the .Touched function on all of them? Im not understanding your issue.
Report Abuse
jtefurd is not online. jtefurd
Joined: 01 May 2010
Total Posts: 952
01 Mar 2015 03:03 PM
That's exactly what I want to do lol
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
01 Mar 2015 03:06 PM
You only attach the event to one part. Insert your event connection into the loop, like this:


function onTouched(limb)
local character = limb.Parent
local player = game.Players:GetPlayerFromCharacter(character)
player.leaderstats.Gold.Value=player.leaderstats.Gold.Value+1
gm.Parent=game.Lighting
end

c=game.Workspace:GetChildren()
for _,v in pairs(c) do
if v.Name=="GoldModel" then
local gm=v
gm.GoldBase.Transparency=1
gd=gm.GoldDetector
gd.Transparency=1
gd.Touched:connect(onTouched)
end
end
Report Abuse
XtremeTemper is not online. XtremeTemper
Joined: 02 Mar 2012
Total Posts: 1774
01 Mar 2015 03:06 PM
The model "GoldModel", does it have multiple gold called "Gold"? so like

-Gold Model
--Gold
--Gold
--Gold
--Gold
--Gold
--Gold
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
01 Mar 2015 03:09 PM
Also, changing onTouched to what Xtreme posted is a good idea. You can't be sure that what is touching the gold is a character.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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