I can only chat for one time

(This is the second post since the last post was sucks)

  1. What do you want to achieve?
    I want to make the NPC chat’s whenever the prompt is triggered. The problem is it only trigger once and when I want to trigger again it didn’t work like show nothin’.

  2. What is the issue? Include screenshots / videos if possible!

It won’t trigger for the second time No errors or any output.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried so many ways, remote events, disable the local script and more.

I really know the problem is below but I don’t know what kind of problem is.

local TalkPromt = script.Parent
local SG = TalkPromt:WaitForChild("TalkGui")
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")
local ExistingSG

TalkPromt.ObjectText = "Talk with " .. script.Parent.Parent.Parent.Name

TalkPromt.Triggered:Connect(function(Player)
	ExistingSG = Player.PlayerGui:FindFirstChild("TalkGui")
	if not ExistingSG then
	  local CloneSG = SG:Clone()
	  CloneSG.Parent = Player.PlayerGui
    end
end)

Any help is appreciated.

4 Likes

do you delete the talkgui after the chat is over?

2 Likes

Yeah, at the local script.

yesyesyes

1 Like

Ok so i inspected it further and i do not think existingSG should be declared outside the function
Can you print some stuff out for when existingSG exists or doesnt exist?

if you delete it locally, the server won’t see that it’s deleted which could cause the bug as your ProximityPrompt Script is a ServerScript.

I did the remote server method where when the chat ends it locally fire to the server and destroy it.

What @keremMCT said is true. Why don’t you just fire a RemoteEvent to the client the moment the ProximityPrompt is triggered, instead of doing all of the cloning stuff. Do that on the client

So I have to fire the Remote Event without using :Clone() ?

Something like this:

serverScript

local TalkPromt = script.Parent
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")

TalkPromt.ObjectText = "Talk with " .. script.Parent.Parent.Parent.Name

TalkPromt.Triggered:Connect(function(Player)
	event:FireClient(player)
end)

localScript

local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")

event.OnClientEvent:Connect(function()
	-- clone the textGui and play the text animation her, instead of on the server
end)

em…, maybe i dont script but i think it would be a no


e

You cannot check for the talkgui when not calling it in the if statement because it outputs an error this will most likely fix ur issue

local TalkPromt = script.Parent
local SG = TalkPromt:WaitForChild("TalkGui")
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")
local ExistingSG

TalkPromt.ObjectText = "Talk with " .. script.Parent.Parent.Parent.Name

TalkPromt.Triggered:Connect(function(Player)
	if not Player.PlayerGui:FindFirstChild("TalkGui") then
	  local CloneSG = SG:Clone()
	  CloneSG.Parent = Player.PlayerGui
    end
end)

Hey, I adjusted your method and it won’t destroy at the end. (found an error which is like Attempting to “Destroy”) And yeah I’ll catch up this tomorrow since it’s 11 AM in my country now.

local TalkPromt = script.Parent
local SG = TalkPromt:WaitForChild("TalkGui")
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")
local ExistingSG

TalkPromt.ObjectText = "Talk with " .. script.Parent.Parent.Parent.Name

TalkPromt.Triggered:Connect(function(Player)
	ExistingSG = Player.PlayerGui:FindFirstChild("TalkGui")
	if not ExistingSG then
	  local CloneSG = SG:Clone()
	  CloneSG.Parent = Player.PlayerGui
event:FireClient(Player)
    end
end)

event.OnServerEvent:Connect(function(Player)
Existing:Destroy
end)

– Client (these weird part of script are not real)

local TextLabel = script.Parent
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")
local v1
local v2
-- v1 and v2 are example

function f1() -- example
romania
end

function f2() -- still example
moldova
end

event.OnClientEvent:Connect(function()
f2("me when")
wait(8)
event:FireServer()
end)

yo on a unrelated note, whats that game your working on called? looks pretty cool

What i mean is there is no reason to clone and destroy the UI on the server. It’s a UI so do it on the client. This is what you should do instead:

ProximityPrompt Script (Server Script):

local TalkPromt = script.Parent
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")

TalkPromt.ObjectText = "Talk with " .. script.Parent.Parent.Parent.Name

TalkPromt.Triggered:Connect(function(Player)
	event:FireClient(Player)
end)

LocalScript (inside of StarterGui or StarterPlayerScripts):

local player = game:GetService("Players").LocalPlayer
local TalkGui = script:FindFirstChild("TalkGui")
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatEvent")

event.OnClientEvent:Connect(function()
	local clonedTalkGui = TalkGui:Clone()
	clonedTalkGui.Parent = player.PlayerGui

	clonedTalkGui.TextLabel.Text = "Dont tell my boss this..." -- do your text animations here

	wait(10) -- time of the animation
	clonedTalkGui:Destroy()
end)

Make sure you put the “TalkGui” inside of the localScript.

1 Like

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