of     1   

AkuFriggus
#183476028Saturday, February 13, 2016 2:42 AM GMT

So I'm making a sword that increases your walkspeed when you equip, then resets it back to what it was before when you unequip the thing is that my game include some speed-enhancing objects, so I don't want to reduce it straight back to 16, or that could become a problem. I want the script to get the player's current walkspeed when they equips the sword, assign it as a variable or something somewhere, and then call back to it when the need arises (when it's unequipped), but I was struggling to do that Can any of you could tell me how I could add that into my script? Thanks in advance
AkuFriggus
#183476288Saturday, February 13, 2016 2:45 AM GMT

BUMP! Please help!
Reset8954098
#183476513Saturday, February 13, 2016 2:48 AM GMT

Well, if multiple scripts are using the same variable, and they are only on one side (server/local preferably only used in local for beginners), then why not just use _G? http://wiki.roblox.com/index.php?title=Global_function I mean, there is more efficient ways to do this, but they require more lines of code, with globals you can literally just set by "_G.walkspeed = " and get by "_G.walkspeed" in the same script or any other that's in the same side.
AkuFriggus
#183476632Saturday, February 13, 2016 2:50 AM GMT

Sorry, quite new to this. Wiki doesn't explain what a _G is, mind offering a small explanation? Thanks!
SkelectroTM
#183476742Saturday, February 13, 2016 2:51 AM GMT

local equipped=false Tool.Equipped:connect(function(mouse) equipped=true end) Tool.Unequipped:connect(function(mouse) equipped=false end) if equipped=true then blah blah walkspeed blah blah = your walkspeed else walkspeed blah blah = your unequipped walkspeed end y-y-you too...
SkelectroTM
#183476808Saturday, February 13, 2016 2:52 AM GMT

if equipped==true* sorry. lol y-y-you too...
AkuFriggus
#183476821Saturday, February 13, 2016 2:52 AM GMT

@electro Please read the post!
SkelectroTM
#183476923Saturday, February 13, 2016 2:54 AM GMT

blah, sorry... I should really read through before posting some irrelevant crap. y-y-you too...
llaserx
#183476973Saturday, February 13, 2016 2:55 AM GMT

function get() local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:wait() local h = char.Humanoid.WalkSpeed return h end if get() then print ("" ..get()) end http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$2,881 Tx343 (づ ゚ ³ ゚)づ
cpmoderator12345
#183477013Saturday, February 13, 2016 2:55 AM GMT

_G is a table in Lua that stores all the global variables. If you store a variable there, you can access it in other scripts. like this: -- script 1 _G.foo = "bar" -- script 2 print(_G.foo) --the output is bar https://www.youtube.com/watch?v=onhFH7jpq2c
AkuFriggus
#183477032Saturday, February 13, 2016 2:55 AM GMT

@xlaser Thank you so much!
AkuFriggus
#183477102Saturday, February 13, 2016 2:56 AM GMT

@cp Thanks for the explanation! _G is irrelevant in this case though, I just wanted to get a char's walkspeed, it's good now though, thanks guys!
Reset8954098
#183477680Saturday, February 13, 2016 3:06 AM GMT

local Player = game:GetService("Players").LocalPlayer -- I don't know exactly what you're doing, but this would be the 'Player' Instance we shall need :^) local WalkSpeed -- Don't exactly want to set this in the if statement, or the rest of the script can't access it :U if Player.Character and Player.Character:FindFirstChild("Humanoid") then --Checking if the Player has a Character, and a Humanoid WalkSpeed = Player.Character.Humanoid.WalkSpeed -- http://wiki.roblox.com/index.php?title=API:Class/Humanoid/WalkSpeed end -- That was just a example, after that if statement it would have the current Player's WalkSpeed stored in the value "WalkSpeed", but you don't necessarily need a value. local Player = game:GetService("Players").LocalPlayer -- For this example, I wont have the if statement to check if the player has a Character. Player.Character.Humanoid.WalkSpeed = Player.Character.Humanoid.WalkSpeed + 10 -- This will give the Player 10 more WalkSpeed, so if they had 16 before now they have 26. You could use subtraction as well to make them slower. I hope this was more helpful!

    of     1