Note: I wasn't sure whether you were using a ClickDetector or a tool based on your code and your question. This answer includes both scenarios.
ClickDetector
You shouldn't be indexing the Value property of your object. Instead, save the actual object as a variable. Additionally, make sure this is a server script. Local scripts will not run in the workspace.
function DrinkWater(player)
local DrinkWater = player.leaderstats.Strength
DrinkWater.Value = DrinkWater.Value + 1
script.Parent.Parent:Destroy()
end
script.Parent.MouseClick:Connect(DrinkWater);
Tool
If you're using a tool, all you have to do is use the Activated event. Additionally, you'll have to use a remote event, as changes to an object inside the player by the client will not replicate to the server.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteEvent")
local tool = script.Parent
tool.Activated:Connect(function()
Remote:FireServer()
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = Instance.new("RemoteEvent")
Remote.Parent = ReplicatedStorage
Remote.OnServerEvent:Connect(function(player)
if player:FindFirstChild("leaderstats") then
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1
end
end)
Also, semicolons are unnecessary in Lua. You can add them like you did freely, but it can make your code appear cluttered sometimes.
##Resources:
Remote Events
##Accept and upvote if this helps!
3 comments
Wouldn't the best solution to just have a script in the tool and then have the script change the leaderstats? That way there isn't insanely high remote queues
It appears my answer was functional from the beginning, it's a Script-grab. You've been scammed, I assumed that Activated stopped working because that happened a few times during experimental tweaks to the Lua Engine
i didnt know there was anything wrong with Activated, but i havent actually been on roblox in a few months, so maybe you're right