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

My script is suppose to do a function if happen = true, but the first part of it isent working?

Asked by
danglt 185
5 years ago
Edited 5 years ago

My script will run and the first part will work changing tvalue but for some reason after that when i make happen = true after that it makes it true but then the happen.Changed function doesent activate, I have no idea why.

I put a print under the changed function and I got no print, so the problem is the Changed Function not working in the beginning

local vipid = 5785777

local Players = game:GetService("Players")

local ews = game.Workspace.EventModel
local efolder = game.Lighting.EventModels
local evalues = game.ReplicatedStorage.EventValues
local tvalue = game.ReplicatedStorage.Values.tvalue
local aevent = game.ReplicatedStorage.Values.aevent
local acevent = game.ReplicatedStorage.Values.caevent
local happen = game.ReplicatedStorage.Values.happen
local aname = game.ReplicatedStorage.Values.ename
local money = game.ReplicatedStorage.Values.money

local events = {"FloorIsLava","Event","BlackHole"}



tvalue.Value = 5          --------------------------- PROBLEM STARTS HERE
        wait(1)
        tvalue.Value = 4
        wait(1)
        tvalue.Value = 3
        wait(1)
        tvalue.Value = 2
        wait(1)
        tvalue.Value = 1
        wait(1)
        happen.Value = true
        wait()

happen.Changed:Connect(function()
    local apick = math.random(1,3)
    if happen.Value == true and acevent.Value == true then
        happen.Value = false
        if aevent.Value == "FloorIsLava" then
            aname.Value = "FloorIsLava"
            aevent.Value = ""
            acevent.Value = false
            wait()
            print("AFloorIsLava")
            local fur = efolder.FloorIsLava.Furniture
            local lava = efolder.FloorIsLava.Lava
            fur.Parent = ews
            tvalue.Value = 15
            wait(1)
            tvalue.Value = 14
            wait(1)
            tvalue.Value = 13
            wait(1)
            tvalue.Value = 12
            wait(1)
            tvalue.Value = 11
            wait(1)
            tvalue.Value = 10
            wait(1)
            tvalue.Value = 9
            wait(1)
            tvalue.Value = 8
            lava.Parent = ews
            wait(1)
            tvalue.Value = 7
            wait(1)
            tvalue.Value = 6
            wait(1)
            tvalue.Value = 5
            wait(1)
            tvalue.Value = 4
            wait(1)
            tvalue.Value = 3
            wait(1)
            tvalue.Value = 2
            wait(1)
            tvalue.Value = 1
            wait(1)
            tvalue.Value = 0
            lava.Parent = efolder.FloorIsLava
            fur.Parent = efolder.FloorIsLava
for i, player in pairs(Players:GetPlayers()) do
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
        player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
            else    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
    end

            end
aname.Value = "Intermission"
        tvalue.Value = 5
        wait(1)
        tvalue.Value = 4
        wait(1)
        tvalue.Value = 3
        wait(1)
        tvalue.Value = 2
        wait(1)
        tvalue.Value = 1
        wait(1)
        happen.Value = true


        elseif aevent.Value == "BlackHole" then
            aevent.Value = ""
            aname.Value = "BlackHole"
            acevent.Value = false
            wait()
            print("BlackHole")
            happen.Value = false
            game.Workspace.Map.Ground.Velocity = Vector3.new(30,0,0)
            local bh = game.Lighting.EventModels.BlackHole
            bh.Parent = game.Workspace.EventModel
            for i, player in pairs(Players:GetPlayers()) do
                player.Character.Humanoid.PlatformStand = true
end
tvalue.Value = 15
            wait(1)
            tvalue.Value = 14
            wait(1)
            tvalue.Value = 13
            wait(1)
            tvalue.Value = 12
            wait(1)
            tvalue.Value = 11
            wait(1)
            tvalue.Value = 10
            wait(1)
            tvalue.Value = 9
            wait(1)
            tvalue.Value = 8
            wait(1)
            tvalue.Value = 7
            wait(1)
            tvalue.Value = 6
            wait(1)
            tvalue.Value = 5
            wait(1)
            tvalue.Value = 4
            wait(1)
            tvalue.Value = 3
            wait(1)
            tvalue.Value = 2
            wait(1)
            tvalue.Value = 1
            wait(1)
            tvalue.Value = 0
            bh.Parent = game.Lighting.EventModels
            game.Workspace.Map.Ground.Velocity = Vector3.new(0,0,0)
            for i, player in pairs(Players:GetPlayers()) do
                player.Character.Humanoid.PlatformStand = false
                aname.Value = "Intermission"
        for i, player in pairs(Players:GetPlayers()) do
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
        player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
            else    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50

            end
aname.Value = "Intermission"
        tvalue.Value = 5
        wait(1)
        tvalue.Value = 4
        wait(1)
        tvalue.Value = 3
        wait(1)
        tvalue.Value = 2
        wait(1)
        tvalue.Value = 1
        wait(1)
        happen.Value = true
end
        end
end
    elseif happen.Value == true and acevent.Value == false then
        if apick == 1 then
                        aevent.Value = ""
            aname.Value = "BlackHole"
            acevent.Value = false
            wait()
            print("BlackHole")
            happen.Value = false
            game.Workspace.Map.Ground.Velocity = Vector3.new(30,0,0)
            local bh = game.Lighting.EventModels.BlackHole
            bh.Parent = game.Workspace.EventModel
            for i, player in pairs(Players:GetPlayers()) do
                player.Character.Humanoid.PlatformStand = true
end
tvalue.Value = 15
            wait(1)
            tvalue.Value = 14
            wait(1)
            tvalue.Value = 13
            wait(1)
            tvalue.Value = 12
            wait(1)
            tvalue.Value = 11
            wait(1)
            tvalue.Value = 10
            wait(1)
            tvalue.Value = 9
            wait(1)
            tvalue.Value = 8
            wait(1)
            tvalue.Value = 7
            wait(1)
            tvalue.Value = 6
            wait(1)
            tvalue.Value = 5
            wait(1)
            tvalue.Value = 4
            wait(1)
            tvalue.Value = 3
            wait(1)
            tvalue.Value = 2
            wait(1)
            tvalue.Value = 1
            wait(1)
            tvalue.Value = 0
            bh.Parent = game.Lighting.EventModels
            game.Workspace.Map.Ground.Velocity = Vector3.new(0,0,0)
            for i, player in pairs(Players:GetPlayers()) do
                player.Character.Humanoid.PlatformStand = false
                aname.Value = "Intermission"
                end
        for i, player in pairs(Players:GetPlayers()) do
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
        player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
            else    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
    end

            end
aname.Value = "Intermission"
        tvalue.Value = 5
        wait(1)
        tvalue.Value = 4
        wait(1)
        tvalue.Value = 3
        wait(1)
        tvalue.Value = 2
        wait(1)
        tvalue.Value = 1
        wait(1)
        happen.Value = true
        elseif apick == 2 then
            happen.Value = false
            aname.Value = "FloorIsLava"
        print("FloorIsLava")
        print("AFloorIsLava")
            local fur = efolder.FloorIsLava.Furniture
            local lava = efolder.FloorIsLava.Lava
            fur.Parent = ews
            tvalue.Value = 15
            wait(1)
            tvalue.Value = 14
            wait(1)
            tvalue.Value = 13
            wait(1)
            tvalue.Value = 12
            wait(1)
            tvalue.Value = 11
            wait(1)
            tvalue.Value = 10
            wait(1)
            tvalue.Value = 9
            wait(1)
            tvalue.Value = 8
            lava.Parent = ews
            wait(1)
            tvalue.Value = 7
            wait(1)
            tvalue.Value = 6
            wait(1)
            tvalue.Value = 5
            wait(1)
            tvalue.Value = 4
            wait(1)
            tvalue.Value = 3
            wait(1)
            tvalue.Value = 2
            wait(1)
            tvalue.Value = 1
            wait(1)
            tvalue.Value = 0
            lava.Parent = efolder.FloorIsLava
            fur.Parent = efolder.FloorIsLava
for i, player in pairs(Players:GetPlayers()) do
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
        player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
            else    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
    end

            end
aname.Value = "Intermission"
        tvalue.Value = 5
        wait(1)
        tvalue.Value = 4
        wait(1)
        tvalue.Value = 3
        wait(1)
        tvalue.Value = 2
        wait(1)
        tvalue.Value = 1
        wait(1)
        happen.Value = true
        elseif apick == 3 then
            happen.Value = false
            aname.Value = "event3"
        print("event3")
        for i, player in pairs(Players:GetPlayers()) do
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
        player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
            else    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
    end

            end
aname.Value = "Intermission"
        tvalue.Value = 5
        wait(1)
        tvalue.Value = 4
        wait(1)
        tvalue.Value = 3
        wait(1)
        tvalue.Value = 2
        wait(1)
        tvalue.Value = 1
        wait(1)
        happen.Value = true
aname.Value = "Intermission"
        tvalue.Value = 5
        wait(1)
        tvalue.Value = 4
        wait(1)
        tvalue.Value = 3
        wait(1)
        tvalue.Value = 2
        wait(1)
        tvalue.Value = 1
        wait(1)
        happen.Value = true
        end
        end

    end)
0
Your script requires that both acevent and happen are true, not just happen, check that acevent is true at the same time SerpentineKing 3885 — 5y
0
There is a spot for that... elseif happen.Value == true and acevent.Value == false then... Also as i stated if i put a print under the changed, It dosent print danglt 185 — 5y
1
I'd recommend learning how to use for loops. User#25115 0 — 5y
0
Are you sure that "Changed" is a valid event of "happen", since it should at least print if it is SerpentineKing 3885 — 5y
View all comments (2 more)
0
Yes, as if i change it manually it works danglt 185 — 5y
0
Good lord... if that isn't spaghetti code then I don't know what is. T0XN 276 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

The Changed event hasn't been registered yet by your code, and therefore never runs. You have to move it before you change the value if you want it to run.

--This is what you have, will never print "It changed!"
myValue.Value = 5
myValue.Changed:Connect(function()
    print("It changed!")
end)
--This is what you should have, this will print "It changed!"
myValue.Changed:Connect(function()
    print("It changed!")
end)
myValue.Value = 5
0
I don't have access to studios right now because I'm on a school chromebook but when I get home ill see if it works and ill accept danglt 185 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This isnt an answer i just wanted to fix your gross indention and add some basic for loops. On line 108 i think there was an extra end, i commented it out.

local vipid = 5785777

local Players = game:GetService("Players")

local ews = game.Workspace.EventModel
local efolder = game.Lighting.EventModels
local evalues = game.ReplicatedStorage.EventValues
local tvalue = game.ReplicatedStorage.Values.tvalue
local aevent = game.ReplicatedStorage.Values.aevent
local acevent = game.ReplicatedStorage.Values.caevent
local happen = game.ReplicatedStorage.Values.happen
local aname = game.ReplicatedStorage.Values.ename
local money = game.ReplicatedStorage.Values.money

local events = {"FloorIsLava","Event","BlackHole"}

tvalue.Value = 5
for i = 1, 5 do
    tvalue.Value = tvalue.Value -1     --------------------------- PROBLEM STARTS HERE
        wait(1)
end

happen.Value = true
wait()

happen.Changed:Connect(function()
    local apick = math.random(1,3)
    if happen.Value == true and acevent.Value == true then
        happen.Value = false
        if aevent.Value == "FloorIsLava" then
            aname.Value = "FloorIsLava"
            aevent.Value = ""
            acevent.Value = false
            wait()
            print("AFloorIsLava")
            local fur = efolder.FloorIsLava.Furniture
            local lava = efolder.FloorIsLava.Lava
            fur.Parent = ews
            tvalue.Value = 15
            wait(1)
            for i = 1, 7 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            lava.Parent = ews
            for i = 1, 8 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            lava.Parent = efolder.FloorIsLava
            fur.Parent = efolder.FloorIsLava
            for i, player in pairs(Players:GetPlayers()) do
                if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
                else 
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
                end
            end
            aname.Value = "Intermission"
            tvalue.Value = 5
            for i = 1, 5 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            happen.Value = true

        elseif aevent.Value == "BlackHole" then
            aevent.Value = ""
            aname.Value = "BlackHole"
            acevent.Value = false
            wait()
            print("BlackHole")
            happen.Value = false
            game.Workspace.Map.Ground.Velocity = Vector3.new(30,0,0)
            local bh = game.Lighting.EventModels.BlackHole
            bh.Parent = game.Workspace.EventModel
            for i, player in pairs(Players:GetPlayers()) do
                player.Character.Humanoid.PlatformStand = true
            end
            tvalue.Value = 15
            for i = 1, 15 do
                tvalue.Value = tvalue.Value - 1
            wait(1)
        end

        bh.Parent = game.Lighting.EventModels
        game.Workspace.Map.Ground.Velocity = Vector3.new(0,0,0)
        for i, player in pairs(Players:GetPlayers()) do
            player.Character.Humanoid.PlatformStand = false
            aname.Value = "Intermission"
            if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
                    else
                player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
                    end
        aname.Value = "Intermission"
            tvalue.Value = 5
        for i = 1, 5 do
            tvalue.Value = tvalue.Value - 1
            wait(1)
        end
            happen.Value = true
    end
    --end
    elseif happen.Value == true and acevent.Value == false then
            if apick == 1 then
            aevent.Value = ""
            aname.Value = "BlackHole"
            acevent.Value = false
            wait()
            print("BlackHole")
            happen.Value = false
            game.Workspace.Map.Ground.Velocity = Vector3.new(30,0,0)
            local bh = game.Lighting.EventModels.BlackHole
            bh.Parent = game.Workspace.EventModel
            for i, player in pairs(Players:GetPlayers()) do
                player.Character.Humanoid.PlatformStand = true
            end
            tvalue.Value = 15
            for i = 1, 15 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            bh.Parent = game.Lighting.EventModels
            game.Workspace.Map.Ground.Velocity = Vector3.new(0,0,0)
            for i, player in pairs(Players:GetPlayers()) do
                player.Character.Humanoid.PlatformStand = false
                aname.Value = "Intermission"
            end
            for i, player in pairs(Players:GetPlayers()) do
                if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
                else
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
                end
            end
            aname.Value = "Intermission"
                tvalue.Value = 5
            for i = 1, 5 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
                happen.Value = true
            elseif apick == 2 then
            happen.Value = false
            aname.Value = "FloorIsLava"
            print("FloorIsLava")
            print("AFloorIsLava")
            local fur = efolder.FloorIsLava.Furniture
            local lava = efolder.FloorIsLava.Lava
            fur.Parent = ews
            tvalue.Value = 15
            wait(1)
            for i = 1, 7 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            lava.Parent = ews
            for i = 1, 8 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            lava.Parent = efolder.FloorIsLava
            fur.Parent = efolder.FloorIsLava
            for i, player in pairs(Players:GetPlayers()) do
                if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
                else    
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
                end

            end
            aname.Value = "Intermission"
            tvalue.Value = 5
            for i = 1, 5 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            happen.Value = true
        elseif apick == 3 then
            happen.Value = false
            aname.Value = "event3"
            print("event3")
            for i, player in pairs(Players:GetPlayers()) do
                if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,vipid) then
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50 + 20
                else
                    player.leaderstats.Events.Value = player.leaderstats.Events.Value + 1
                    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
                end

            end
            aname.Value = "Intermission"
            tvalue.Value = 5
            for i = 1, 5 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
            happen.Value = true
            aname.Value = "Intermission"
                tvalue.Value = 5
            for i = 1, 5 do
                tvalue.Value = tvalue.Value - 1
                wait(1)
            end
                happen.Value = true
            end
        end
end)

Answer this question