And then I of course had the RemoteEvent named “RemoteEvent”
And then I had this script called “PlayAnimScript” that plays the animation, which had the following script: local AnimPlaying = false game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,animationID) local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID="..animationID if AnimPlaying == false then local loadedAnimation = game.Workspace[player.Name].Humanoid:LoadAnimation(animation) loadedAnimation:Play() AnimPlaying=true wait(1) local headLifts = player.leaderstats.headLifts headLifts.Value = headLifts.Value+1 AnimPlaying=false end end)
And I was wondering how I would get this area to work: local headLifts = player.leaderstats.headLifts headLifts.Value = headLifts.Value+1
How would I get the specific player who clicked the button in the first place?
All this script worked before adding the leaderstats area into the server script, which I’m just leaving in there for now because I know I’ll need it
-- LocalScript inside of your button
local animationID = 5647630275
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=" .. animationID
local loadedAnimation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation)
script.Parent.MouseButton1Click:Connect(function()
animation:Play() -- animations played on client replicate to the server
end)
What you could also do instead (and this would work much better anyways) would be to add an Animation object inside of the script with the ID pasted into it. Then, you can replace my code with this code:
-- LocalScript inside of your button, with an Animation object called "Animation" with your animation ID inside of it
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local animation = humanoid:LoadAnimation(script.Animation)
script.Parent.MouseButton1Click:Connect(function()
animation:Play()
remoteEvent:FireServer()
end)
-- ServerScript inside of ServerScriptService
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remoteEvent.OnServerEvent:Connect(function(plr)
plr.leaderstats.headLifts.Value += 1
end)
Also make sure to read the comments, as they will help you set this up properly. Let me know if there is a problem
I meant for you to disregard my other script, and to try this script instead. Make sure to read the comments in the code so that you set the script up properly.