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

How do functions triggered by RemoteEvents work?

Asked by 3 years ago
Edited 3 years ago

So I have a script that removes a first (character selection) gui and makes adjustments to a second gui. I use a client to server RemoteEvent technique.

script 'GameIntroHandler': (located in ReplicatedStorage -> gui: ScreenGui -> the script: GameIntroHandler

local RepStore = game:GetService("ReplicatedStorage")
local GameIntroEvent = RepStore:WaitForChild("GameIntroEvent")

local screen = script.Parent:WaitForChild("Screen")
local MadeByText = screen:FindFirstChild("MadeBy")
local GameLogo = screen:FindFirstChild("Image")
local Sound = script.HorrorSound

GameIntroEvent.OnServerEvent:Connect(function(Player)
    print("Screen Is Visible")
    wait(1)
    for i = 1,100 do
        wait(.004)
        MadeByText.TextTransparency = MadeByText.TextTransparency -.01
    end
    wait(1)
    for i = 1,100 do
        wait(.004)
        MadeByText.TextTransparency = MadeByText.TextTransparency +.01
    end
    wait(2.5)
    Sound:Play()
    wait(0.1)
    GameLogo.ImageTransparency = 0
    MadeByText.Visible = false
    wait(3)
    for i = 1,100 do
        wait(.004)
        screen.BackgroundTransparency = screen.BackgroundTransparency +.01
    end
    wait(0.5)
    for i = 1,100 do
        wait(.004)
        GameLogo.ImageTransparency = GameLogo.ImageTransparency +.01
    end
    GameLogo.Visible = false
    screen.Visible = false
end)

local script 'LocalCharacterChoice': (located in StarterPlayer -> StarterPlayerScripts -> the script: LocalCharacterChoice

local RepStore = game:GetService("ReplicatedStorage")
local ChoiceEvent = RepStore:WaitForChild("ChoiceEvent")
local GameIntroEvent = RepStore:WaitForChild("GameIntroEvent")

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local StarterGui = game:GetService("StarterGui")
local ScreenGui = RepStore:WaitForChild("ScreenGui"):Clone()
ScreenGui.Parent = PlayerGui

local gui = ScreenGui.Main
local secondgui = ScreenGui.Screen

local guiCharacter1 = gui.Character1
local guiCharacter2 = gui.Character2
local guiCharacter3 = gui.Character3
local whitetext = gui.WhiteText
local redtext = gui.RedText

local soundservice = game:GetService("SoundService")
local soundeffect = soundservice:WaitForChild("SelectSoundEffect")

local b1, b2, b3 = gui.Character1, gui.Character2, gui.Character3

b1.MouseButton1Click:Connect(function()
    ChoiceEvent:FireServer(1)
    soundeffect:Play()
    wait(1)
    for i = 0,1,.01 do
        guiCharacter1.ImageTransparency = i 
        guiCharacter2.ImageTransparency = i 
        guiCharacter3.ImageTransparency = i
        whitetext.TextTransparency = i
        whitetext.TextStrokeTransparency = i
        redtext.TextTransparency = i
        redtext.TextStrokeTransparency = i
        wait(0.01)
    end
    gui.Visible = false
    secondgui.Visible = true
    GameIntroEvent:FireServer()
end)
b2.MouseButton1Click:Connect(function()
    ChoiceEvent:FireServer(2)
    soundeffect:Play()
    wait(1)
    for i = 0,1,.01 do
        guiCharacter1.ImageTransparency = i 
        guiCharacter2.ImageTransparency = i 
        guiCharacter3.ImageTransparency = i
        whitetext.TextTransparency = i
        whitetext.TextStrokeTransparency = i
        redtext.TextTransparency = i
        redtext.TextStrokeTransparency = i
        wait(0.01)
    end
    gui.Visible = false
    secondgui.Visible = true
    GameIntroEvent:FireServer()
end)
b3.MouseButton1Click:Connect(function()
    ChoiceEvent:FireServer(3)
    soundeffect:Play()
    wait(1)
    for i = 0,1,.01 do
        guiCharacter1.ImageTransparency = i 
        guiCharacter2.ImageTransparency = i 
        guiCharacter3.ImageTransparency = i
        whitetext.TextTransparency = i
        whitetext.TextStrokeTransparency = i
        redtext.TextTransparency = i
        redtext.TextStrokeTransparency = i
        wait(0.01)
    end
    gui.Visible = false
    secondgui.Visible = true
    GameIntroEvent:FireServer()
end)

I do not get errors and the first gui disappears but nothing shows up on the second gui. The gui loads in but the function is not called. What is the solution?

Thank you in advance!

Answer this question