(This is the second post since the last post was sucks)
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’.
What is the issue? Include screenshots / videos if possible!
It won’t trigger for the second time No errors or any output.
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)
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?
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
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)
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)
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.