Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this script work in game?

Asked by
22To 70
8 years ago

its a serverscriptservice for some reason it wont work.

pcall(function()
    game.Players.PlayerAdded:connect(function(player)
        if game.GamePassService:PlayerHasPass(player,340209466) then
            local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
            cashmoney.Value = cashmoney.Value + 5000
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 25
                    char.Humanoid.Health = char.Humanoid.Health + 25
                    char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed + 8
                    game.Lighting.SpaceSword:Clone().Parent=player.Backpack
                end
            end)
        elseif game.GamePassService:PlayerHasPass(player,340204818) then
            local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
            cashmoney.Value = cashmoney.Value + 1000
        player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    game.Lighting.FrostSword:Clone().Parent=player.Backpack 
        end
    end)

2 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

You were missing a few ends. It will also help if you tab your code properly. You also should not need pcall. This is what will mask any errors you may have, and prevent you or us from finding them.


Solution

Make sure you have an end for every function, if then statement, and loop.


Final Script

game.Players.PlayerAdded:connect(function(player) --You were missing an end for this function.
        if game.GamePassService:PlayerHasPass(player,340209466) then --You were also missing an end for this if then statement.
            local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
            cashmoney.Value = cashmoney.Value + 5000
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 25
                    char.Humanoid.Health = char.Humanoid.Health + 25
                    char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed + 8
                    game.Lighting.SpaceSword:Clone().Parent=player.Backpack
                end
            end)
        elseif game.GamePassService:PlayerHasPass(player,340204818) then
            local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
            cashmoney.Value = cashmoney.Value + 1000
        player.CharacterAdded:connect(function(char)
            if char:WaitForChild("Humanoid") then
                game.Lighting.FrostSword:Clone().Parent=player.Backpack 
            end
        end)
    end
end)

Hopefully this answered your question, if so hit the accept answer button. If you have any questions, feel free to comment below.
0
wrong error apparently, but the problem is that max health,swords, and walkspeed doesnt load, but money does 22To 70 — 8y
Ad
Log in to vote
0
Answered by
rexbit 707 Moderation Voter
8 years ago

I'd suggest using a wait function for the player to fully load.

game.Players.PlayerAdded:connect(function(player) 
        if game.GamePassService:PlayerHasPass(player,340209466) then
            local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
            cashmoney.Value = cashmoney.Value + 5000
            player.CharacterAdded:connect(function(char)
                if char:WaitForChild("Humanoid") then
                    char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 25
                    char.Humanoid.Health = char.Humanoid.Health + 25
                    char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed + 8
                    game.Lighting.SpaceSword:Clone().Parent=player.Backpack
                end
            end)
        elseif game.GamePassService:PlayerHasPass(player,340204818) then
            local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
            cashmoney.Value = cashmoney.Value + 1000
            if char:WaitForChild("Humanoid") then
                game.Lighting.FrostSword:Clone().Parent=player.Backpack 
            end
    end
end)

0
wrong error apparently, but the problem is that max health,swords, and walkspeed doesnt load, but money does 22To 70 — 8y

Answer this question