Remote Events not working and/or player failing to load

Hey developers,

So I need help with this. I have a script that sends the player’s username to a local script which will announce it in the chat. There is the server script then the local script.

local ProximityPrompt = script.Parent
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local TextChatService = game:GetService("TextChatService")
local CooldownStore = DataStoreService:GetDataStore("MeditationCooldowns")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local MeditationSuccessEvent = ReplicatedStorage:WaitForChild("Events", 5):WaitForChild("MeditationSuccess", 5)

local Meditation = script.Parent.Parent.Parent:FindFirstChild("EffectMeditation")
local MedSuccess = script.Parent.Parent.Parent:FindFirstChild("EffectSuccess")

local COOLDOWN_TIME = 1
local SUCCESS_CHANCE = 1

local function getCooldownKey(player)
    return "Cooldown_" .. player.UserId
end

local function getRemainingCooldown(player)
    local key = getCooldownKey(player)
    local lastAttempt = CooldownStore:GetAsync(key)
    if lastAttempt then
        local elapsedTime = os.time() - lastAttempt
        if elapsedTime < COOLDOWN_TIME then
            return COOLDOWN_TIME - elapsedTime
        end
    end
    return 0
end

local function fadeInFrame(player)
    local playerGui = player:FindFirstChildOfClass("PlayerGui")
    if playerGui then
        local whiteGui = playerGui:FindFirstChild("White")
        if whiteGui then
            local frame = whiteGui:FindFirstChildOfClass("Frame")
            if frame then
                frame.BackgroundTransparency = 1
                frame.Visible = true
                local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
                local tween = TweenService:Create(frame, tweenInfo, {BackgroundTransparency = 0})
                tween:Play()
            end
        end
    end
end

local function fadeOutFrame(player)
    local playerGui = player:FindFirstChildOfClass("PlayerGui")
    if playerGui then
        local whiteGui = playerGui:FindFirstChild("White")
        if whiteGui then
            local frame = whiteGui:FindFirstChildOfClass("Frame")
            if frame then
                frame.BackgroundTransparency = 0
                frame.Visible = true
                local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
                local tween = TweenService:Create(frame, tweenInfo, {BackgroundTransparency = 1})
                tween:Play()
            end
        end
    end
end

local function onProximityPromptTriggered(player)
    local ClosedCaptions = require(player.PlayerGui.ClosedCaptions.CaptionModule)
    local remainingCooldown = getRemainingCooldown(player)
    if remainingCooldown > 0 then
        ClosedCaptions.Caption("You must wait ".. math.ceil(remainingCooldown / 60) .. " minutes before trying again.", 5)
        return
    end

    local character = player.Character
    if character then
        character:SetPrimaryPartCFrame(CFrame.new(-0.72, 7.044, -84.09))
        character.PrimaryPart.Anchored = true
    end
    
    script.Parent.Enabled = false
    
    if Meditation then
        for _, descendant in Meditation:GetDescendants() do
            if descendant:IsA("ParticleEmitter") then
                descendant.Enabled = true
            end
        end
    end

    local animation = Instance.new("Animation")
    animation.AnimationId = "rbxassetid://79195079524452"
    local animator = character:FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator")
    local animationTrack = animator:LoadAnimation(animation)
    animationTrack:Play()

    task.wait(5)
    
    if Meditation then
        for _, descendant in Meditation:GetDescendants() do
            if descendant:IsA("ParticleEmitter") then
                descendant.Enabled = false
            end
        end
    end
    
    script.Parent.Enabled = false

    if math.random() < SUCCESS_CHANCE then
        ClosedCaptions.Caption("Your meditation has been accepted by the gods.", 5)
        if MedSuccess then
            for _, descendant in MedSuccess:GetDescendants() do
                if descendant:IsA("ParticleEmitter") then
                    descendant.Enabled = true
                end
            end
		end
		MeditationSuccessEvent:FireAllClients(player.Name)
		task.wait(5)
		fadeInFrame(player)
		task.wait(2)
		if character then
			character:SetPrimaryPartCFrame(CFrame.new(144.354, -154.952, 3.84))
		end
		if character then
			character.PrimaryPart.Anchored = false
		end
		
		for _, descendant in MedSuccess:GetDescendants() do
			if descendant:IsA("ParticleEmitter") then
				descendant.Enabled = false
			end
		end
		animationTrack:Stop()
		animation:Destroy()
		task.wait(2)
		script.Parent.Enabled = true
		fadeOutFrame(player)
		local heavenlySound = SoundService:FindFirstChild("Heavenly")
		if heavenlySound then
			heavenlySound:Play()
		end
		task.wait(2)
		ClosedCaptions.Caption("Go up to the middle and talk to the gods.", 5)
	else
		if character then
			character.PrimaryPart.Anchored = false
		end
        animationTrack:Stop()
        animation:Destroy()
        ClosedCaptions.Caption("Meditation failed. You must wait 15 minutes before trying again.", 5)
        local key = getCooldownKey(player)
		CooldownStore:SetAsync(key, os.time())
		script.Parent.Enabled = true
    end
end

ProximityPrompt.Triggered:Connect(function(player)
    if player:IsA("Player") then
        onProximityPromptTriggered(player)
    end
end)

Here is the local script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")

local MeditationSuccessEvent = ReplicatedStorage:WaitForChild("MeditationSuccess")

MeditationSuccessEvent.OnClientEvent:Connect(function(playerName)
    local generalChannel = TextChatService:FindFirstChild("RBXGeneral")
    if generalChannel then
        generalChannel:DisplaySystemMessage(playerName .. " has successfully meditated!")
    end
end)

And yes, I did test them but no error produced in the output.

:heart: Thanks!

1 Like

I still need help! Thank you! :upside_down_face:

I’m still having issues with this. Please help me!

Currently in the process of trying to help you, but for now you could add print statements to each if statement and what not to make sure everything is firing correctly. Also, sending us the whole script makes it difficult to identify which parts aren’t working.

Edit: I still can’t figure out the exact issue but this is what I did for mine:

local channel

repeat task.wait(0.25)
	channel = textChatService.TextChannels:FindFirstChild("RBXGeneral")
until (channel)

-- do the other stuff --

You need to index the TextChannels before you look for the RBXGeneral.

Here are the changes:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")

local MeditationSuccessEvent = ReplicatedStorage:WaitForChild("MeditationSuccess")

MeditationSuccessEvent.OnClientEvent:Connect(function(playerName)
	local Channels = TextChatService:FindFirstChild("TextChannels")
	if not Channels then return end
	
	local GeneralChannel = Channels:FindFirstChild("RBXGeneral") :: TextChannel
	if not GeneralChannel then return end
	
	GeneralChannel:DisplaySystemMessage(playerName .. " has successfully meditated!")
end)
1 Like

Thank you, but it is still not displaying the message. It is TextChatService by the way.

It might be your server script. To be sure, execute this on the command bar while being on the server then switch to the client to see the result. Code: game.ReplicatedStorage.MeditationSuccess:FireAllClients("TestPlayerName")

That didn’t return anything either. Proof:

And yes, I know I am ment to change the name but I was not bothered to.

@sonic_848

I just noticed that the event isn’t a direct child of ReplicatedStorage? Based on your code, I assumed it was a direct child.

image

(Workspace)
image

It’s in a starterplayer local script.

Change to this:

local MeditationSuccessEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("MeditationSuccess")

@TeamDreams123

1 Like

Thank you so much. An oversight from both of us :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.