Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

is it possible to transfer the value from one leaderstat to another?

Asked by 3 years ago

im trying to grab the value from one leaderstat and put it into another leaderstat, is that possible?

local ui = script.Parent
local player = game.Players.LocalPlayer

while wait() do
    local player = game.Players.LocalPlayer
    ui.Text = ""..player:WaitForChild("Equipped"):FindFirstChild("One").Value
end

function leftClick()
    player.Equipped.One.Value = player.Equipped.Current.Value
end

ui.MouseButton1Click:Connect(leftClick)
0
you shouldnt be using a while loop like that, use GetPropertyChangedSignal, theres no point in concatenating an empty string, what exactly is player.Equipped.One and player.Equipped.Current and are they used on the server? TheBoys810 30 — 3y
0
Player.Equipped.One is the ability equipped in the one slot and Player.Equipped.Current is the selected ability. Say you wanted to equip the fireball ability, you would press the fireball button and the Player.Equipped.Current which is a string would change to "FireBall" then you would press on the number that you want to equip the ability to i.e 1-5. Then when you press on 1 or 5 or whatever- DraconianSG 58 — 3y
0
number between them, it should get the string value from the Current and set it to the Number that you pressed, in this case "One". the empty string is to just display the ability name DraconianSG 58 — 3y
0
okay i understand the one and current now, but you still shouldn't need the empty string, i also didnt realise this earlier but its good practice to use local function over function, although it looks like this code should work unless the values need to be updated on the server too TheBoys810 30 — 3y
View all comments (23 more)
0
I dont understand why it wont work DraconianSG 58 — 3y
0
are the values being updated? you could check in studio playtesting with the explorer, i assume this script is a localscript (it uses LocalPlayer so it has to be), are the values (Equipped.XYZ & Equipped.Current ever accessed on the server? these are the only reasons i could think it isnt working TheBoys810 30 — 3y
0
i dont exactly know what accessed on the server means DraconianSG 58 — 3y
0
like ever called on a server script? DraconianSG 58 — 3y
0
a server script (any Script or ModuleScript (required by a Script and not a LocalScript)) reading the Value of an Equipped Value TheBoys810 30 — 3y
0
no, they arent DraconianSG 58 — 3y
0
it could be that your UserInputService (or whatever you use to detect key presses) implementation isnt working correctly TheBoys810 30 — 3y
0
oh the 1-5 buttons are a ui DraconianSG 58 — 3y
0
the script i put on this post is from the 1 button DraconianSG 58 — 3y
0
oh, well you should try using print to debug your code to see where it stops working TheBoys810 30 — 3y
0
ok ill try that DraconianSG 58 — 3y
0
i put a print in the function before and after the Player.Equipped.One.Value = player.Equipped.Current.Value and neither print came up DraconianSG 58 — 3y
0
then its prboably that theres a gui above the one you want the MouseButton1Click event to be firing, instead its firing the one above, check if theres any guis (invisible or not) above it, it could also be because its a rounded gui and you're accidently clicking the image instead of the actual button TheBoys810 30 — 3y
0
by accidently i mean that the image is above the textbutton, not that you're actually clicking the image but that could be it TheBoys810 30 — 3y
0
i mean in the actual rendering, not the explorer TheBoys810 30 — 3y
0
https://gyazo.com/260d9c6c8a4e4ce1c83074e4d2fe3e3a the white "1" is the button DraconianSG 58 — 3y
0
well it seems like it should be working, i have no idea why it isnt TheBoys810 30 — 3y
0
this is the weirdest thing i have experienced DraconianSG 58 — 3y
0
Oh, i know now, its because a while loop yields infinitely and you havent created a new thread for it, this can be solved with coroutine.wrap/coroutine.new & coroutine.resume or just by using GetPropertyChangedSignal TheBoys810 30 — 3y
0
I was about to say i changed the while loop to player.Equipped.One.Changed:Connect(function(newVal) and that fixed it DraconianSG 58 — 3y
0
alright, thats good to know, but you should use player.Equipped.One.Changed:GetPropertyChangedSignal("Value") instead of .Changed TheBoys810 30 — 3y
0
alright ill do that DraconianSG 58 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

The problem was the While loop

Ad

Answer this question