✓ Accepted answer
Don't name your functions and your variables the same thing. Rename your slurp function to something else. Also, you have to use the assignment operator to add to a value. This is also not a good idea because you're getting LocalPlayer from the script, so I'm assuming you're using a LocalScript. Playing animations or changing value on the client (LocalScript) does not replicate over to the Server, so only the player using the cola will see the effect, or hear it, or even the addition to their leaderstat. If you want the whole server to see it, I'd recommend using a ServerScript. You're also trying to play the audio from StarterPack, not in the actual tool itself.
Fixed LocalScript:
local tool = script.Parent
local slurp = tool.Slurp
local Lplayer = game.Players:GetPlayerFromCharacter(tool.Parent) or tool.Parent.Parent;
local leaderstat = Lplayer.Leaderstats
print(leaderstat)
function playSlurp()
slurp:Play()
wait(0.5)
print("Slurping")
end
local function onActivate()
playSlurp()
wait(0.1)
print("Adding")
leaderstat.Points.Value = leaderstats.Points.Value + 1
print("Added")
end
tool.Activated:Connect(onActivate)
Fixed ServerScript:
local tool = script.Parent
local slurp = tool.Slurp
local Lplayer = game.Players.LocalPlayer
local leaderstat = Lplayer.Leaderstats
print(leaderstat)
function playSlurp()
slurp:Play()
wait(0.5)
print("Slurping")
end
local function onActivate()
playSlurp()
wait(0.1)
print("Adding")
leaderstat.Points.Value = leaderstats.Points.Value + 1
print("Added")
end
tool.Activated:Connect(onActivate)
2 comments
How would I put in the ServerScript?
I found a error in the code. It says local leaderstat = Lplayer.Leaderstats, but leaderstats should ALWAYS be called "leaderstats". No typos or caps.