Alright. I'm very new to scripting. My brother and I have been kind of messing around in studio team create. We decided to make a little simple combat game for us and our friends, and since I'm more familiar with scripting then he is, I've taken over that load of the developing process. All was going well until I attempted to make a shop GUI where the player can obtain items depending on said players amount of kills. I created a leaderstat script (with the help of the Roblox developer wiki) called, "Kills." Stuff was going well, and then I ran into an error. When the player clicks a text button, a local script detects the number of kills the player has. I'm not sure where I went wrong, but it simply doesn't work. Here, I'll show the code.
local player = game.Players.LocalPlayer local reps = game.ReplicatedStorage local stats = player:FindFirstChild("leaderstats").Kills.Value local button = script.Parent local dtext = ("Sword - 10 Kills") button.Text = dtext script.Parent.MouseButton1Click:connect(function() if stats >=10 then game.ReplicatedStorage["Sword"]:clone().Parent = player.Backpack elseif stats <10 then button.Text = ("Not enough kills!") wait(2) button.Text = dtext end end)
This is the code from the localscript located inside the textbutton. Heres my leaderstat code:
local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local kills = Instance.new("IntValue") kills.Name = "Kills" kills.Value = 0 kills.Parent = leaderstats end game.Players.PlayerAdded:Connect(onPlayerJoin)
This is inside of a script located in ServerScriptService. When tested, the text on the button changes to, "You don't have enough kills!" Which obviously, I don't. But once I change my players Kills value to 15, (I've tried 10 as well,) I get the same message. I do not see any error in the output window.
Thanks for reading this much-it is a little wordy. I'll take any help I can get, please and thanks.
In your variable "stats" you are defining it as what the Kills value is currently, it will not update by any changes. So simply remove the .Value when defining stats and add it to the stats variables on line 10 and 12
if you need an example:
local e = 1 local yeet = e print(yeet) e = 2 print(yeet)
output: 1(x2)