How to access a Player's Character using ServerScriptService

I made a gamepass for when you buy it you get custom animation which works fine, but now im working on a button to disable the animations script, but cant figure out how to access the players character, since im still kinda new to scripting, so what im trying to do is, if they click the button, it turns the animations off, if its clicked again it turns it back on.
but cant find the Animation script inside the player
What I tried so far is
– The Script that gets the Gui and enable it if player has the gamepass which works inside ServerScriptService

game.Players.PlayerAdded:Connect(function(player)
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(player.UserId, 13303076) then
player.PlayerGui.AnimEnabler.Enabled = true
else
player.PlayerGui.AnimEnabler.Enabled = false
end
end)

Script that makes the gui work and function in StarterGui

local OnandOff = script.Parent.OnAndOff – Gets the Button in the Gui
local player = game.Players.LocalPlayer:GetCharacterFromPlayer() – Gets the Local Player

local Animations = player.Animations – Gets the Animations script inside the player

OnandOff.MouseButton1Click:Connect(function()
if Animations.Disabled == true then
Animations.Disabled = false
OnandOff.Text = “Animations On”
else
Animations.Disabled = true
OnandOff.Text = “Animations Off”
end
end)

sorry if everything is confusing,

2 Likes

The Player object has a Character property.

local character = game.Players.LocalPlayer.Character
1 Like

Thanks for telling me, I didn’t know

1 Like

You should also add local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:wait() just incase the character isn’t loaded yet or spawned

Mark his reply as a solution, so the topic can be closed and people what the answer is!