Little help on checking leaderstat values?
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.
01 | local player = game.Players.LocalPlayer |
02 | local reps = game.ReplicatedStorage |
03 | local stats = player:FindFirstChild( "leaderstats" ).Kills.Value |
04 | local button = script.Parent |
05 | local dtext = ( "Sword - 10 Kills" ) |
09 | script.Parent.MouseButton 1 Click:connect( function () |
11 | game.ReplicatedStorage [ "Sword" ] :clone().Parent = player.Backpack |
13 | button.Text = ( "Not enough kills!" ) |
This is the code from the localscript located inside the textbutton. Heres my leaderstat code:
01 | local function onPlayerJoin(player) |
02 | local leaderstats = Instance.new( "Folder" ) |
03 | leaderstats.Name = "leaderstats" |
04 | leaderstats.Parent = player |
06 | local kills = Instance.new( "IntValue" ) |
09 | kills.Parent = leaderstats |
12 | 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.