Hello,
I have a script that data stores and loads stat points. For example,
local endurance = Instance.new("IntValue", folder)
endurance.Name = "Endurance"
I am looking to make the endurance actually do things. What I am trying to accomplish is for every endurance stat point, their walk speed is increased by 0.1. How can I accomplish this? I tried a for i loop and it didn’t work, and I can’t find any documentation on it.
That won’t work, as the script that changes the endurance value starts off in a local script and gets what ever the text button is named and fires a event with the name of the stat’s textbutton and a server script recieves it and ups whatever stat is recieved, and it’s in a different script than my main stat script, which means theres no way to determine if the stat point being upped is. If this doesn’t make sense, heres my scripts:
Local script
local statsRemote = game:GetService("ReplicatedStorage"):WaitForChild("Stats") -- the stats remote event put inside a variable
local enabled = false -- a cooldown value, prevents button spamming
for _, button in pairs(script.Parent:GetChildren())do -- we loop through the frame
if button:IsA("TextButton") then -- if the thing we're currently at is a textbutton then...
button.MouseButton1Click:Connect(function() -- if that textbutton was clicked then...
if enabled == false then -- if the cooldown value is false then...
enabled = true -- we turn it to true, so it fails the check above...
statsRemote:FireServer("AddStatpoints", string.sub(button.Name, 1, string.len(button.Name) - 6))
script["Fallout (1) - Click"]:Play()
wait(0.25)
enabled = false
end
end)
end
end
Regular script:
local statsRemote = game:GetService("ReplicatedStorage"):WaitForChild("Stats") -- the stats remote event put inside a variable
function checkForLevelUp(Player) -- we create a function which checks whether the player should level up
local data = Player:FindFirstChild("Data") -- we put the player's data folder inside a variable
if data:WaitForChild("Exp").Value >= data:WaitForChild("ExpMax").Value then -- if the player's exp is over or equal to the max exp, hes able to reach till he levels up then...
data:WaitForChild("Exp").Value = 0 -- we reset the player's exp
data:WaitForChild("ExpMax").Value = data:WaitForChild("ExpMax").Value + (data:WaitForChild("ExpMax").Value / 2) -- we raise the max exp limit
data:WaitForChild("Level").Value = data:WaitForChild("Level").Value + 1 -- we add one level
data:WaitForChild("Statpoints").Value = data:WaitForChild("Statpoints").Value + math.random(10, 20) -- we give a random amount of statpoints (between 2-6)
end
end
statsRemote.OnServerEvent:Connect(function(Player, Val, ToWhat) -- if the stats remote event was fireservered then...
local Data = Player:WaitForChild("Data") -- we put the player's data folder inside a variable
if Val == "AddStatpoints" and Data:WaitForChild("Statpoints").Value > 0 then -- if the script is told to add a statpoint to a stat and there are enough statpoints then...
Data:WaitForChild("Statpoints").Value = Data:WaitForChild("Statpoints").Value - 1 -- we remove 1 statpoint
Data:WaitForChild(tostring(ToWhat)).Value = Data:WaitForChild(tostring(ToWhat)).Value + 1
end
end)
game.Players.PlayerAdded:Connect(function(Player) -- if a player joins then...
repeat wait() until Player:FindFirstChild("Data") -- we make the script wait till the player's data is avaible
checkForLevelUp(Player) -- we check the player, if hes ready to level up
Player:FindFirstChild("Data").Exp.Changed:Connect(function() -- once the exp changes
checkForLevelUp(Player) -- we check the player, if hes ready to level up
end)
end)
Wdym it wont work? In the server script where you increase the endurance, just update the players stats there. If you mean it won’t save or something then setup a starter character script to add the endurance for you.