I’ve got 2 issues with my script atm and I need some help. I’m fairly new to scripting and I’ve been using this devforum the past few days to get some help with my scripts and it seems to be working so I thought, why not try again.
local GPS = game:GetService("MarketplaceService")
local Replicated = game:GetService('ReplicatedStorage')
local CheckForPass = Replicated:WaitForChild("CheckForGamepass")
local character = game.Workspace.Player
local plr = game.Players:GetPlayerFromCharacter(character)
CheckForPass.OnServerEvent:Connect(function(Player)
if GPS:UserOwnsGamePassAsync(plr.UserId,9508134) then
local tool = game:GetService("ServerStorage"):FindFirstChild("Tool"):Clone()
tool.Parent = plr:WaitForChild("Backpack")
end
end)
local function getPlayerFromCharacter(character)
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if player.Character == character then
return player
end
end
end
First off, the example found here (under Code Examples #1) shows that local character = game.Workspace.Player should work, but it does not. (I get the error “3:54:30.982 - Player is not a valid member of Workspace”)
I think that it should fix the script in it’s entirety if I’m able to get the local character somehow.
The reason that I have to do it through a FireServer and not a PlayerAdded event is because when you spawn in, you change teams through a team changer before you get to play, thus, removing the tools if I used a PlayerAdded event.
Any workarounds to the character issue and other issues within my script would be greatly appreciated.
Cheers,
Artic