#Remote Event Help

30 messages · Page 1 of 1 (latest)

broken cedar
#

I'm making a script to where an npc is animated and once you go into a designated area then the npc will change animations and talk(animated gui text label on screen) and I have two Local scripts.
LocalScript(the gui local script)

local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local textLabel = script.Parent
local typingSpeed = 0.1
local n = 0
local function playTypeSound()
    local soundId = "rbxassetid://9120299407"
    local sound = Instance.new("Sound")
    sound.SoundId = soundId
    sound.Parent = textLabel
    sound:Play()
end

local function typewriterAnimation(text)
    for i = 1, #text do
        textLabel.Text = string.sub(text, 1, i)
        if n < 5 then
            playTypeSound()
        end
        wait(typingSpeed)
    end
    n = n + 1
    if n == 4 then
        typingSpeed = 0.4
    end
end
remoteEvent.OnClientEvent:Connect(function(text)
    typewriterAnimation(text)
end)
#

AnimationScript(under starterplayerscripts)

local part = game.Workspace.Designated
local animation = script.Animation
local anim2 = script.Anim2
local anim3 = script.anim3
local humanoid = game.Workspace.Nas.Humanoid
local animationTrack = humanoid:LoadAnimation(animation)
local anim2Track = humanoid:LoadAnimation(anim2)
local anim3Track = humanoid:LoadAnimation(anim3)
local debounce = false 

local function playNext()
    anim2Track:Play()
    print("Anim2 playing")
    wait(anim2Track.Length)
    anim3Track:Play()
    print("Anim3 playing")
    local text = "hello"
    game.ReplicatedStorage.RemoteEvent:FireServer(text)
    wait(6)
    text = "whats poppin"
    game.ReplicatedStorage.RemoteEvent:FireServer(text)
    wait(6)
end

local function onTouched(other)
    local character = other.Parent
    local humanoid = character:FindFirstChildWhichIsA("Humanoid")
    wait(1)
    if humanoid and not debounce then
        debounce = true
        playNext()
        wait(5)
    end
end
animationTrack:Play()
part.Touched:Connect(onTouched)

Problem is, the ```lua
remoteEvent.OnClientEvent:Connect(function(text)

doesnt seem to be called
keen dew
#

im struggling to understand

#

which one is the server side

#

@broken cedar

broken cedar
#

both are client sided

broken cedar
# keen dew im struggling to understand

its that I want each player to go through the game as if its single player but they can play it together so like a player touches a part and it activates the animation then it activates the text gui

#

but it only shows for whoever touched the part (the animation and the text)

keen dew
#

why are u using remote events if u want it so be client sided

broken cedar
#

honestly it was server to client then i wanted to change it half way in and Im not sure how to call functions from another local script from a local script

#

if you could help me with that then that would work just fine

broken cedar
#

@keen dew 😔

keen dew
#

u want to connect 2 local scripts

kindred kindleBOT
#

studio** You are now Level 8! **studio

keen dew
#

to share variables?

broken cedar
#

yes

#

well

#

no

#

just like

#

Lets say I have 2 local scripts both in different folders and I want to activate a function that is held in script 2 from script 1

keen dew
#

do it in 1 local script

broken cedar
#

i tried combining it both but it didnt seem to show the text

kindred kindleBOT
#

studio** You are now Level 6! **studio

broken cedar
#
local part = game.Workspace.Designated
local animation = script.Animation
local anim2 = script.Anim2
local anim3 = script.anim3
local humanoid = game.Workspace.Nas.Humanoid
local animationTrack = humanoid:LoadAnimation(animation)
local anim2Track = humanoid:LoadAnimation(anim2)
local anim3Track = humanoid:LoadAnimation(anim3)
local debounce = false -- Flag to track if the part is currently being touched
local textLabel = game.StarterGui.ScreenGui.firstT -- Reference to the TextLabel
local typingSpeed = 0.1  -- Adjust the speed of typing (lower is faster)
local n = 0

local function playTypeSound()
    local soundId = "rbxassetid://9120299407"  -- Replace with your sound ID
    local sound = Instance.new("Sound")
    sound.SoundId = soundId
    sound.Parent = textLabel  -- Play the sound through the TextLabel
    sound:Play()

end


local function typewriterAnimation(text)

    for i = 1, #text do
        textLabel.Text = string.sub(text, 1, i)
        if n < 5  then
            playTypeSound()
        end
        wait(typingSpeed)

    end
    n = n+1
    if n == 4 then
        typingSpeed = 0.4

    end

end

local function playNext()
    anim2Track:Play()
    print("Anim2 playing")
    wait(anim2Track.Length)
    anim3Track:Play()
    print("Anim3 playing")
    local text = "hello"
    typewriterAnimation(text)
    wait(6)
    text = "whats poppin?"
    typewriterAnimation(text)
    wait(6)
end

local function onTouched(other)

    local character = other.Parent
    local plr = character:FindFirstChildWhichIsA("Humanoid")

    -- If touched by a player's humanoid, stop the animation and play Anim2
    wait(1)
    if plr and not debounce then
        debounce = true
        playNext()
        wait(5)
    end
end
animationTrack:Play()

part.Touched:Connect(onTouched)

It plays everything normally except the text doesnt show

keen dew
#
local part = game.Workspace.Designated
local animation = script.Animation
local anim2 = script.Anim2
local anim3 = script.anim3
local humanoid = game.Workspace.Nas.Humanoid
local animationTrack = humanoid:LoadAnimation(animation)
local anim2Track = humanoid:LoadAnimation(anim2)
local anim3Track = humanoid:LoadAnimation(anim3)
local debounce = false 
local textLabel = game.StarterGui.ScreenGui.firstT
local typingSpeed = 0.1  
local n = 0

local function playTypeSound()
    local soundId = "rbxassetid://9120299407" 
    local sound = Instance.new("Sound")
    sound.SoundId = soundId
    sound.Parent = textLabel  
    sound:Play()
end

local function typewriterAnimation(text)
    for i = 1, #text do
        textLabel.Text = string.sub(text, 1, i)
        if n < 5 then
            playTypeSound()
        end
        wait(typingSpeed)
    end
    n = n + 1
    if n == 4 then
        typingSpeed = 0.4
        n = 0 
    end
end

local function playNext()
    anim2Track:Play()
    print("Anim2 playing")
    wait(anim2Track.Length)
    anim3Track:Play()
    print("Anim3 playing")
    local text = "hello"
    typewriterAnimation(text)
    wait(6)
    text = "whats poppin?"
    typewriterAnimation(text)
    wait(6)
end

local function onTouched(other)
    local character = other.Parent
    local plr = character:FindFirstChildWhichIsA("Humanoid")

    if plr and not debounce then
        debounce = true
        playNext()
        wait(5)
        debounce = false 
    end
end

animationTrack:Play()
part.Touched:Connect(onTouched)
broken cedar
#

it didnt work @keen dew

keen dew
#

have u uploaded the animations?

broken cedar
#

yes

#

the animations work fine

#

its just the text gui