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: Get money on touch script problem.

Previous Thread :: Next Thread 
Alphaminusone is not online. Alphaminusone
Joined: 19 Jun 2016
Total Posts: 419
16 Mar 2017 06:33 PM

This was my original script. It had one flaw. Since it was inserted into coins dropped by npcs when killed the coins sometimes collded with the npcs instead.

amnt = 7
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Money")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
script.Parent:remove()
end
end

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


Then I asked for help to make this script. Which is supposed to only give cash if it is an actual player. But now it doesn't do anything at all. Can someone edit it so it gives money but only to an actual player.


amnt = 7 --How much money
deb = true --To prevent multiple touching

script.Parent.Touched:connect(function(hit)

if deb == true then
deb = false
local player = game.Players[hit.Parent.Name] --Should get the player (Let me know if not)
local stats = game.Players.player.leaderstats.Money --From player to it's stats.
stats.Value = stats.Value + amnt --Giving the player cash.
script.Parent:Destroy() --Removing the egg after it gave cash.
end

end)







Report Abuse
Disaster_Scripts is not online. Disaster_Scripts
Joined: 10 May 2016
Total Posts: 2310
16 Mar 2017 06:41 PM
game.Players:Get Player From Character(hit.Parent)

No space.
Report Abuse
Alphaminusone is not online. Alphaminusone
Joined: 19 Jun 2016
Total Posts: 419
16 Mar 2017 06:51 PM
It says player is not a valid member of players.
Report Abuse
Disaster_Scripts is not online. Disaster_Scripts
Joined: 10 May 2016
Total Posts: 2310
16 Mar 2017 06:52 PM
It works fine for me.
Report Abuse
hasang1 is not online. hasang1
Joined: 09 Nov 2012
Total Posts: 903
16 Mar 2017 06:55 PM
Someone forgot all about accessing instances requiring a name, not another instance.

local amnt,deb=7,true
script.Parent.Touched:connect(function(hit)
if deb == true then
deb = false
local player = game.Players:FindFirstChild'hit.Parent.Name'
if not player then return end
local stats=player:FindFirstChild'leaderstats'
if not stats then return end
local money=stats:FindFirstChild'Money'
if not moneythen return end
money.Value = money.Value + amnt --Giving the player cash.
script.Parent:Destroy() --Removing the egg after it gave cash.
end
end)




HAX.
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