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: Want sword damage to be based on a leaderstat

Previous Thread :: Next Thread 
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
30 Jul 2014 10:12 PM
So I haven't been on ROBLOX like I used to religiously be on in about 2-3 years and I wanna get back into it. I've forgotten quite a bit about scripting. All I'm trying to do is figure out how to take the variable number from a leaderstat and turn it into how much damage the sword's damage is going to be putting out. Help me out please lol it sounds so simple but I'm totally lost.
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 02:33 PM
I've been trying to experiment and somehow I think this is what it might look similar to inside the SwordScript, but still no luck:



local player = script.Parent.Parent.Humanoid:playerFromCharacter()

local damage = player.leaderstats.ATK.Value


local slash_damage = player.leaderstats.ATK.Value
local lunge_damage = player.leaderstats.ATK.Value
Report Abuse
ehern11 is not online. ehern11
Joined: 23 Apr 2011
Total Posts: 1541
31 Jul 2014 08:24 PM
um. where is this script located in?
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 08:35 PM
The part of the script I've shown is part of a script in "SwordScript" which is inside the tool itself, making the tool the parent of the script. Leaderstats is a group given to each player under the "Players" service, which is why I'm having difficulty figuring out how to make the damage from this sword that of something inside a different service.
Report Abuse
ehern11 is not online. ehern11
Joined: 23 Apr 2011
Total Posts: 1541
31 Jul 2014 08:37 PM
you cant get the player from the Players service.
Report Abuse
ehern11 is not online. ehern11
Joined: 23 Apr 2011
Total Posts: 1541
31 Jul 2014 08:38 PM
mistyped that; i meant character
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 08:41 PM
So the workspace model of the player that's actually holding the sword can't have a variable from a leaderstat value linked to it in any way?
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 08:42 PM
To clarify I'm making an RPG and I just want it so whenever someone levels up their Attack (ATK) stat will go up as well, increasing their weapon damage (the sword damage) over time as you level up.
Report Abuse
ehern11 is not online. ehern11
Joined: 23 Apr 2011
Total Posts: 1541
31 Jul 2014 08:46 PM
just make a intvalue named damage, parent it into the tool and try using something like;
if player.level.Value = player.level.Value +1 then
tool.damage.Value = tool.damage.Value + 50
i.e
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
31 Jul 2014 08:50 PM
It's not that hard :)

local tool = script.Parent
local char = tool.Parent
local plr = game.Players:findFirstChild(char.Name)

local slash_dmg = plr.leaderstats.ATK.Value
local lunge_dmg = plr.leaderstats.ATK.Value
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 09:06 PM
YES Stealth king oh my god thank you so much! Much much thanks <3
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 09:16 PM
Well it looked like it would work but unfortunately still nothing. It looked good and promising though lol \:
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 09:20 PM
Also ehern that would be a good idea except I'm not sure how to get a xp/gold intvalue inserted into a player's workspace model as soon as they enter the game, like how you can give leaderstats as soon as a player enters the game.
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
31 Jul 2014 09:21 PM
"Well it looked like it would work but unfortunately still nothing. It looked good and promising though lol \:"

Any errors in output?

It should work inside a script inside the tool of yours
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 09:27 PM
5 r = game:service("RunService")
6
7 local tool = script.Parent
8 local char = tool.Parent.Name
9 local plr = game.Players:findFirstChild(char)
10
11 local slash_damage = plr.leaderstats.atk.Value*0.5
12 local lunge_damage = plr.leaderstats.atk.Value
13
14 sword = script.Parent.Handle
15 Tool = script.Parent


output says "Script 'Players.Player1.Backpack.Sword.SwordScript', Line 11"
Report Abuse
Adam4111 is not online. Adam4111
Joined: 27 Feb 2008
Total Posts: 113
31 Jul 2014 09:29 PM
Also in red output says: "Players.Player1.Backpack.Sword.SwordScript:11: attempt to index local 'plr' (a nil value)"
Report Abuse
mathchamp is not online. mathchamp
Joined: 22 Oct 2007
Total Posts: 320
31 Jul 2014 11:15 PM
9 local plr = game.Players:GetPlayerFromCharacter(char)


Also, instead of setting slash_damage and lunge_damage once on initialization, I would suggest doing something like this:

local slash_damage
local lunge_damage

function UpdateDamage()
slash_damage = plr.leaderstats.atk.Value*0.5
lunge_damage = plr.leaderstats.atk.Value
end

plr.leaderstats.atk.Changed:connect(UpdateDamage)
UpdateDamage()


This way, the damage will actually update whenever the player's stat changes, without the player having to respawn or replace their sword. Note that even then you will still have issues where if the player drops the sword and someone else picks it up, it will still go by the original player's attack stat. To make it work even after the sword switches hands, you'll want to add some code so that the connection gets disconnected when the sword is dropped, then when someone else picks up the sword, re-evaluate plr, reconnect to the event, and call UpdateDamage() again. I'll leave the actual coding for you as an exercise ;)
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