Need help accessing the player via a server script

Im a beginner to scripting and I need help accessing a value i put in starterplayerscripts
The places marked with “— boolean value” are where i need to access the player.

Heres my code:


local DS = game:GetService('DataStoreService')
local elbow = DS:GetDataStore("elbow")
local players = game:GetService('Players')




---Elbow_Smash---

local Part = script.Parent.Parent
local ProximityPrompt = game.Workspace.Tool.ProxPart.ProximityPrompt

ProximityPrompt.Triggered:connect(function(Player)

if Player and Player.Character then
       Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - 1000
game.Players:FindFirstChild(Player).PlayerScripts.Abilities.elbow_smash.Value = true — boolean value
wait(1)
local success, errorMessage = pcall(function()
elbow:SetAsync(Player.UserId.."elbow", game.Players:FindFirstChild(Player).PlayerScripts.Abilities.elbow_smash.Value) --boolean value
end)
if success then
print("elbow_Smash saved")
else
warn(errorMessage)
print("data not saved yuh oh")
end

end
end)
local data
game.Players.PlayerAdded:Connect(function(player)
local success, errorMessage = pcall(function()

data = elbow:GetAsync(player.UserId.."elbow")
end)
if success then
player.PlayerScripts.Abilities.elbow_smash.Value = data — Boolean value
print("importing data for:".. player.UserId)
else
print("import failed")
warn(errorMessage)
end

end)
--Elbow Smash--

I don’t understand why you are trying to use game.Players:FindFirstChild(Player) where Player is already the player in question? I think you are sort of mixing up the thinking about what the player is.

1 Like

i tried Player.PlayerScripts but it didnt work so i started trying other methods in getting them and the :findfirstchild(Player) happened to be the last method i tried. The reason i did that was because i ran a test and printed out Player and it printed my username so i thought i could use :findfirstchild(Player) to get the player.

Players:FindFirstChild(Player) is the exact the same as simply Player. How is it not working?

The code is effectively doing workspace:FindFirstChild(workspace.something.Name), but yes, OP is using FindFirstChild incorrectly

player is an instance and print found the name and just outputted that but I believe findfirstchild doesn’t convert it into a string so you’d need to do player.name if you want to use findfirstchild

1 Like

ok i’ll try when i get the chance.

documentation says it only takes strings with no mention of anything else

You can’t access PlayerScripts from a Script.

You mean you’ll do this?
game.Players:FindFirstChild(Player.Name)?
That’s redundant, don’t use FindFirstChild at all here.


You’ll need to store the elbow_smash and other such data in the script as a variable or in the Player object itself.

2 Likes

Are you suggesting i create a variable for the data? Also the script is in a proximity prompt. Im gonna try creating a bool value in serverscriptservice with players name on it.