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

Why wont this work? is it possible to merge it together?

Asked by
22To 70
8 years ago

Ok,so this is part of a script but I am trying to make it so if the person owns the game pass they get double XP and Double Gold, so I made two values name "PassXP" and "PassGold" but it seems to not give them the double,the non-owners get the original values "XP" and "Gold"

function Died()
local tag = script.Parent.Human:FindFirstChild("creator") 
    if tag ~= nil then 
        if tag.Value ~= nil then 
            local Leaderstats = tag.Value:FindFirstChild("leaderstats") 
            if script.Parent.SETTINGS:FindFirstChild("XP") ~= nil and script.Parent.SETTINGS:FindFirstChild("Gold") ~= nil then
                Module.AddStats(Leaderstats, script.Parent.SETTINGS.XP.Value, script.Parent.SETTINGS.Gold.Value)
            else print("Can't find XP and Gold!")
            end
        end
    end
end

script.Parent.Human.Died:connect(Died)
local passid = 382015968
local GamePassService = game:GetService("GamePassService")
if GamePassService:PlayerHasPass(player, passid) then
function Died()
local tag = script.Parent.Human:FindFirstChild("creator") 
    if tag ~= nil then 
        if tag.Value ~= nil then 
            local Leaderstats = tag.Value:FindFirstChild("leaderstats") 
            if script.Parent.SETTINGS:FindFirstChild("PassXP") ~= nil and script.Parent.SETTINGS:FindFirstChild("PassGold") ~= nil then
                Module.AddStats(Leaderstats, script.Parent.SETTINGS.XP.Value, script.Parent.SETTINGS.Gold.Value)
            else print("Can't find XP and Gold!")
            end
        end
    end
end

1 answer

Log in to vote
0
Answered by
legosweat 334 Moderation Voter
8 years ago

Ok, so I see some problems where you have two functions of Died(), which is not proper. So we'll put the two functions together. In this case, you do not need two values, so you can get rid of the "PassGold"/"PassXP".

I'm guessing 'Module' and 'player' have been defined already.

EDIT Now that I know player is not defined and its a regular script...

So here's the script result:


local GamePassService = game:GetService("GamePassService") -- Get the gmaepass service local passid = 382015968 -- The pass id which is needed for x2 xp game.Players.PlayerAdded:connect(function(player) -- gets the player when joined player.CharacterAdded:connect(function(Character) -- fires when character is added Character.Humanoid.Died:connect(function() -- connects to humanoid's death local tag = Character:FindFirstChild("creator") if tag ~= nil then if tag.Value ~= nil then local Leaderstats = tag.Value:FindFirstChild("leaderstats") -- Get the leaderstats if GamePassService:PlayerHasPass(player, passid) then -- If the player has the pass, we proceed to giving the player x2 gold/xp if script.Parent.SETTINGS:FindFirstChild("XP") ~= nil and script.Parent.SETTINGS:FindFirstChild("Gold") ~= nil then Module.AddStats(Leaderstats, script.Parent.SETTINGS.XP.Value*2, script.Parent.SETTINGS.Gold.Value*2) -- Times the values by two, which is giving them x2 the gold/xp else print("Can't find XP and Gold!") end else -- If they do not have the pass, the function proceeds here if script.Parent.SETTINGS:FindFirstChild("XP") ~= nil and script.Parent.SETTINGS:FindFirstChild("Gold") ~= nil then Module.AddStats(Leaderstats, script.Parent.SETTINGS.XP.Value, script.Parent.SETTINGS.Gold.Value) -- Give them the regular rates else print("Can't find XP and Gold!") end end end end end) end) end)

Hope this helped!

0
no work D: gives nothing... doesnt even give the original XP and Gold 22To 70 — 8y
Ad

Answer this question