So I am fairly new to scripting and I have made a simple code where you click on a stick and it increases a value found in the local player's PlayerScripts named "stickvalue" by 1 but it is doing absolutely nothing the code is:
local Player = game:GetService("Players").LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Character:FindFirstChildOfClass("Humanoid") local clickdetector = script.Parent.ClickDetector local stickvalue = game.Players.LocalPlayer.PlayerScripts.stickvalue.Value clickdetector.MouseClick:Connect(function(player) stickvalue = stickvalue + 1 end)
Can you show me where the stickvalue IntValue is created? and also, you can do "stickvalue += 1" to add one to the current value, and you can do "stickvalue -= 1" to take away 1 from the current value.
Judging from the clickdetector part, its safe to say you put the local script in workspace. That is plain wrong. local scripts cannot work outside the localplayer, or the character of the local player.
Instead, use a server script. MouseClick function has a parameter that helps you here and that parameter is called playerWhoClicked (you can change to player, like you did in your local script, or you can change to something funny like stopusingscriptviewer).
so, put a server script (normal script) at where you put the local script, and in the script, put the following code:
local clickdetector = script.Parent.ClickDetector game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = leaderstats local stickvalue = Instance.new("DoubleConstrainedValue",leaderstats) stickvalue.Name = Sticks stickvalue.MinValue = 0 stickvalue.MaxValue = 1e303 end) clickdetector.MouseClick:Connect(function(stopusingscriptviewerdumbo) -- casually trolling dex users with parameters local stickvalue = stopusingscriptviewerdumbo.leaderstats.Sticks.Value -- same thing but we use the funni parameter as a reference to the player since server scripts can't access local player. stickvalue = stickvalue + 1
also, local Character and local Humanoid was useless since you didn't even use the humanoid or character.
lemme say this again. **Don't use local scripts, use normal scripts, or else this will not work. **
Why wait for somebody to rescue you from a tower when you can rescue yourself
I found a simple way
local clickdetector = script.Parent.ClickDetector clickdetector.MouseClick:Connect(function(player) player.Character.stickvalue.Value += 1 end)
i then put a stickvalue IntValue inside the StarterCharacterScripts folder and now when you click on the stick it works. ez