Lol sorry sorry for not properly stating the question! Yes, I’m getting some errors in the script but I’m trying to learn as much as I can!
So… with that being said, what’re the errors you’re getting?
the recall function at the bottom is giving me a “did you forget to close the function at line 25” error
Right, I can’t help but notice you didn’t really bracket all your code into a block. It’s sort of bugging me, so if you could do that, please do so.
As for the error… It’s because you’re missing an end.
There is no line “25” here so where did you get the error!
There are probably lines above he didn’t include.
Ok, Then can he show them to us so we know what line 25 is.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
loadHealth(player)
end)
end)
So, aren’t you supposed to have 1 end for each function I only see one but you have 3.
You have two functions, and you’re missing your end)
right above the last end, here.
Let’s go through this together:
In the very first line, you’re defining a connection function for when a player is added, with a parameter being that player.
In the second line, you’re doing the same, just for the character instead.
Now we’re calling a custom function in the third line with the passing parameters being the player. You only called ONE end)
, while that second function doesn’t necessarily ever have an end, therefore you need to wrap it in one more end)
.
I hope I helped!
Try to indent some of this where needed. This is the best I can do so if it does not work try something else.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
loadHealth(player)
end)
end)
local MarketplaceService = game:GetService(“MarketplaceService”)
local GampassID = 18664894
local humanoid = game.Players:WaitForChild(“Humanoid”)
local function loadHealth(player)
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function()
local human = plr.Character:WaitForChild(“Humanoid”)
local character = player.Character
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GampassID)
end)
end)
if hasPass and human then
human.MaxHealth = 150
end
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
loadHealth(player)
end)
end)
I don’t understand why when a player joins the game it loads a function that involves checking when a player joins, when your current error is fixed, this will stop your script from even running as when the player joins it checks for when the player joins the game again which since they would already be in would never happen
…No, there’s a specific connection that’s made with this function. This code is pre-initialized, meaning that it runs even before a player is in the game, so this does run when ANY player joins, really.
If you check the current code the function runs when the character of a player who joins is added
Oh, I see. Yes, I read wrong, there is really no reason to do this when the character is added.
Another thing I noticed is there is a missing end to close the function itself
Hence the problem listed above.
after editing the script, there is an unknown global.
Try this one.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
loadHealth(player)
end)
end)
local MarketplaceService = game:GetService(“MarketplaceService”)
local GampassID = 18664894
local humanoid = game.Players:WaitForChild(“Humanoid”)
local function loadHealth(player)
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function()
local human = plr.Character:WaitForChild(“Humanoid”)
local character = player.Character
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GampassID)
if hasPass and human then
human.MaxHealth = 150
end
end)
end)
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
loadHealth(player)
end)
end)
Right click and click “Format Document” to see the script in a better formatted way. Then you can find the visual errors.