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: It is not using the variable I set

Previous Thread :: Next Thread 
usfirepilot is not online. usfirepilot
Joined: 17 Jan 2013
Total Posts: 684
28 Sep 2014 08:36 PM
I have this script, and I have a variable called "player"

local player = game.Workspace:FindFirstChild(hit.Parent.Name)

But this line here:

local wins = game.Players.player.leaderstats:FindFirstChild("Wins:")

Does not want to use the variable! Why wont it use it? :(
Here is the full script:

script.Parent.Touched:connect(function(hit)
local player = game.Workspace:FindFirstChild(hit.Parent.Name)
if player then
local humanoid = player:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 16
end
local wins = game.Players.player.leaderstats:FindFirstChild("Wins:")
print(wins.Name)
if wins then
wins.Value = wins.Value + 1
print(wins.Value)
end
end
end)
Report Abuse
usfirepilot is not online. usfirepilot
Joined: 17 Jan 2013
Total Posts: 684
28 Sep 2014 08:37 PM
Also, here is the output:

19:35:21.018 - player is not a valid member of Players
19:35:21.022 - Script 'Workspace.Level 1.End.Script', Line 8
19:35:21.023 - Stack End
19:35:21.023 - Disconnected event because of exception
Report Abuse
usfirepilot is not online. usfirepilot
Joined: 17 Jan 2013
Total Posts: 684
28 Sep 2014 08:39 PM
Anyone -.-?
Report Abuse
whale is not online. whale
Joined: 09 Apr 2008
Total Posts: 1445
28 Sep 2014 08:40 PM
local wins = game.Players[player].leaderstats..... etc
Report Abuse
usfirepilot is not online. usfirepilot
Joined: 17 Jan 2013
Total Posts: 684
28 Sep 2014 08:42 PM
Now its this output:

19:42:07.724 - Workspace.Level 1.End.Script:8: bad argument #2 to '?' (string expected, got userdata)
19:42:07.725 - Script 'Workspace.Level 1.End.Script', Line 8
19:42:07.726 - Stack End
19:42:07.727 - Disconnected event because of exception
Report Abuse
whale is not online. whale
Joined: 09 Apr 2008
Total Posts: 1445
28 Sep 2014 08:44 PM
local wins = game.Players[tostring(player)].leaderstats..... etc
Report Abuse
Rapster2 is not online. Rapster2
Joined: 16 Oct 2009
Total Posts: 1865
28 Sep 2014 08:45 PM
or just do game.Players[player.Name]
Report Abuse
usfirepilot is not online. usfirepilot
Joined: 17 Jan 2013
Total Posts: 684
28 Sep 2014 08:46 PM
Thanks!
Report Abuse
Cawlonee is not online. Cawlonee
Joined: 03 Mar 2014
Total Posts: 2687
28 Sep 2014 08:46 PM
local character = game.Workspace:FindFirstChild(hit.Parent.Name)
local player = game.Players:FindFirstChild(hit.Parent.Name)

local wins = game.Players.player.leaderstats:FindFirstChild("Wins:")


so

script.Parent.Touched:connect(function(hit)
local character = game.Workspace:FindFirstChild(hit.Parent.Name)
if character then
local humanoid = character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.WalkSpeed = 16
end
local wins = player.leaderstats:FindFirstChild("Wins:")
print(wins.Name)
if wins then
wins.Value = wins.Value + 1
print(wins.Value)
end
end
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