The reason why your code won't run for both if statements is because in your first if statement, you are deleting the script in which the code is being ran regardless of which state it comes to.
To fix this just remove the parts where you are deleting the script.
local player = game.Players.LocalPlayer
local char = player.Character
local GPS = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:Connect(function(plr)
if GPS:UserOwnsGamePassAsync(plr.UserId,7853571) then
local Part = script.Parent:WaitForChild("HumanoidRootPart")
script.Light.Parent = Part
Part.Light.Brightness = 1.5
Part.Light.Range = 9
else
local Part = script.Parent:WaitForChild("HumanoidRootPart")
script.Light.Parent = Part
Part.Light.Brightness = 1
Part.Light.Range = 6
end
if GPS:UserOwnsGamePassAsync(plr.UserId,7854035) then
char.Humanoid.MaxHealth = 125
char.Humanoid.Health = 125
else
char.Humanoid.MaxHealth = 100
char.Humanoid.Health = 100
end
end)
But you have another problem, it seems like this code is located inside the character as well that it is a localscript, you want this code to only be located in one place and running on the server. So put this code into a normal script and put this code in the ServerScriptService, after this we need to fix the code to reflect this including changes to how light is put into the HumanoidRootPart
make sure to put the light instance inside the script
local light=script.Light
local GPS = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:Connect(function(plr)
local char=plr.Character
if GPS:UserOwnsGamePassAsync(plr.UserId,7853571) then
local Part = char:WaitForChild("HumanoidRootPart")
local l=light:Clone()
l.Brightness = 1.5
l.Range = 9
l.Parent=Part
else
local Part = char:WaitForChild("HumanoidRootPart")
local l=light:Clone()
l.Brightness = 1
l.Range = 6
l.Parent=Part
end
if GPS:UserOwnsGamePassAsync(plr.UserId,7854035) then
char.Humanoid.MaxHealth = 125
char.Humanoid.Health = 125
else
char.Humanoid.MaxHealth = 100
char.Humanoid.Health = 100
end
end)
1 comment
I've done as to what you have instructed. Now all is left is to fix the error output "ServerScriptService.GPS Check:8: attempt to index local 'char' (a nil value)". However, when I put them in StarterCharacterScript, the error was gone. But, I'll stick with ServerScriptService.