*In the video above, I press yes on the confirm prompt and it teleports me to my destination. But when I try it with the other part to return back, it teleports me to the first destination.
The code I have is a module script that is accessed via another module script to do actions because of my game’s framework → local script with a remote event firing.*
Here is the Module Script code(snippet)
local RES = game:GetService('ReplicatedStorage')
local remotes = RES.Remotes
local interactableTypes = {
-- don't worry about Test & Gamepass. Focus on `Prompt`
Test = function(plr, obj)
print(`{plr.Name} has tested for the object: {obj.Name} | {plr.Name} && {obj.Name}`)
end,
Gamepass = function(plr, obj)
if obj.Name == 'Gamepass' then
local gamepassId = obj:FindFirstChild('GamepassID') :: StringValue
print(`{plr.Name} | {gamepassId.Value}`)
MPS:PromptGamePassPurchase(plr, tonumber(gamepassId.Value))
end
end,
Prompt = function(plr, obj)
remotes.SC_PromptPopupTP:FireClient(plr, obj)
end,
}
--[=[
_G is not used for Lib folder.
To require modules in Lib folder, use require() function
]=]--
local Lib__Interactable = {}
Lib__Interactable.__index = Lib__Interactable
function Lib__Interactable.New(typeName: string, object: Instance, activationDistance: number, actionText: string)
local self = setmetatable({
}, Lib__Interactable)
self._object = object
------------
self._proximityPrompt = Instance.new('ProximityPrompt') :: ProximityPrompt
self._proximityPrompt.Parent = self._object :: any
self._proximityPrompt.MaxActivationDistance = activationDistance :: number
self._proximityPrompt.ActionText = actionText :: string
self._proximityPrompt.Triggered:Connect(function(plr)
interactableTypes[typeName::string](plr, self._object)
end)
return self
end
return Lib__Interactable
Here is the Module Script code to access the above module(snippet)
Interactable.New('Prompt', workspace.Interactables.Shop, 10, `bob's shop is cool`)
Interactable.New('Prompt', workspace.Interactables.ShopReturn, 10, `go back to wolrd`)
And finally here is the Local Script code(snippet ofc)
remotes.SC_PromptPopupTP.OnClientEvent:Connect(function(obj)
prompt.Visible = true
promptText.Text = obj:WaitForChild('PromptText').Value :: StringValue
yesButton.MouseButton1Click:Connect(function()
prompt.Visible = false
local dest = obj:FindFirstChild('Destination').Value
print(dest)
hrp.CFrame = CFrame.new(dest.Position :: ObjectValue)
end)
-- code used when u press the no button
end)
Explorer for any needed help
The ObjectValue Destination is the object that I want the player to go to.
For ShopReturn(the teleporter that was bugged) has it’s Destination ObjectValue set to Dest
And these are my RemoteEvents stored in ReplicatedStorage
It would be very much appreciated if anybody could help me with this issue as teleporting is a big factor in the game I’m developing.
Could you add a print statement below that and see if it fires twice?
And, for that to be firing twice, it looks like the proximity prompt needs to be ‘fired’/interacted with twice as each time there is an interaction that function is fired. So, maybe the same proximity prompt has multiple objects, but that doesn’t seem to be the case based on the code I’m reading here:
function Lib__Interactable.New(typeName: string, object: Instance, activationDistance: number, actionText: string)
local self = setmetatable({
}, Lib__Interactable)
self._object = object
------------
self._proximityPrompt = Instance.new('ProximityPrompt') :: ProximityPrompt
self._proximityPrompt.Parent = self._object :: any
self._proximityPrompt.MaxActivationDistance = activationDistance :: number
self._proximityPrompt.ActionText = actionText :: string
self._proximityPrompt.Triggered:Connect(function(plr)
interactableTypes[typeName::string](plr, self._object)
end)
return self
end
I hope that helps, my best advice is to add print statements throughout the process the code is taking. See where it stops printing two value, and why it printing two values at the end.
I added print statements for when the RemoteEvent fires and for the position of the Destination.
I honestly have no idea what’s happening because I only fire the RemoteEvent SC_PromptPopupTP once.
This code fires the RemoteEvent.
Then this snippet sees if the player pressed the Yes button on the prompt and prints “fired” but it only prints once because it’s only fired once and not twice. I don’t think it’s something to do with my ObjectValue but I digress.
Could you add a line under where the player gets teleported to disconnect the event?
yesButton.MouseButton1Click:Connect(function() is firing twice as it looks like the old firing of the first teleport is still connected to it, meaning that the yesButton function would be firing twice.
I assume the same thing would be happening for the noButton function.
local connection
local function nameHere()
prompt.Visible = false
local dest = obj:FindFirstChild('Destination').Value
print(dest)
hrp.CFrame = CFrame.new(dest.Position :: ObjectValue)
connection :Disconnect()
end)
connection = yesButton.MouseButton1Click:Connect(nameHere)
If the noButton stuff is not working, then I think the noButton function also needs to have the same disconnection stuff to happen:
local connectionYes
local connectionNo
remotes.SC_PromptPopupTP.OnClientEvent:Connect(function(obj)
print('fired')
prompt.Visible = true
promptText.Text = obj:WaitForChild('PromptText').Value :: StringValue
local function clickYes()
prompt.Visible = false
local dest = obj:FindFirstChild('Destination').Value
print(dest.Position)
hrp.CFrame = CFrame.new(dest.Position :: ObjectValue)
connection:Disconnect()
end
local function clickNo()
-- Code for the no button goes here
end
connectionYes = yesButton.MouseButton1Click:Connect(clickYes)
connectionNo = noButton.MouseButton1Click:Connect(clickNo)
end)
The code isn’t break-ing out of the function above it I don’t think, so I’m not sure why the no button would stop working. I’d add a print statement to see if the code runs after the disconnections. They should, but yeah.
noButton.MouseButton1Click:Connect(function()
prompt.Visible = false
if obj:FindFirstChild('NPC') then
local npc = obj:FindFirstChild('NPC').NPC :: Model
local msgs = {
`You scammer!`,
`You'll pay for this!`,
`I know who u are {plr.Name}`,
`Why u do this to me :(`,
`You noob!`
}
interactable:ChatNPC(npc:FindFirstChild('Head'), msgs[math.random(1, #msgs)], 'Red')
local face: Decal = npc:FindFirstChild('Head'):FindFirstChild('face')
face.Texture = 'rbxassetid://910076130'
RES.Sounds.Boom:Play()
task.wait(2)
face.Texture = 'rbxasset://textures/face.png'
end
end)
I seem to have fixed the issue by disconnecting both events right after either of them fire. If both are not deleted when one is pressed, they accumulate over time, causing issues.