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.