It would help since disabling streaming enabled made it work (I’m guessing as I haven’t tried all the coins in the map only some but they were far away from the spawnlocation)
Yeah thats what I thought, oh and also the code that the other person posted would not fix the issue, changing a prompts exclusivity won’t have any affect under replication issues.
I will try my best and provide you with a fix tommorow as in my GMT time-line its pretty late.
How you know it won’t work? By making it globally it make it only to use server side without client one which can maybe fix issue without FilteringEnabled.
Yeah but the current type of the script is a localscript, and the current problem is the following:
Basically they made a loop statement which will collect all prompts that are currently available for the client. And since Streaming is enabled that means that all of the prompts are not loaded yet. So I will pull a tricky solution against that. I will explain more tomorrow, I can understand your concern and I am sorry for the confusion, I hope I cleared your questions.
Edit: Fixed logical mistakes
I can’t use :WaitForChild() in a in pairs loop can I?
Wouldn’t work, WaitForChild calls are used to wait for a instance which has the name you setted at the calls parameter, but we need some sort of waitforIsA or something. I am about to go to sleep right now so I sadly cant provide you with further assistance, but probably tommorow I will post a example script that would fix the issue (if nothing goes wrong)
So here is the code that could possibly fix your issue without having to disable StreamingEnabled, everything is explained in comments, if you have any questions just ask me, if this fixed the issue you can mark this as “Solved”:
Code:
local Frame = script.Parent
local TS = game:GetService("TweenService")
local CoinFolder : Folder = game.Workspace:WaitForChild("Money", math.huge)
-- math.huge will force waitforchild to wait for ever instead of saying "infinite yield"
local Player = game:GetService("Players").LocalPlayer
local Value = Player.Character:WaitForChild("Purse")
local Text = script.Parent.TextLabel
local MoneySound = script.MoneySOund
local RunService = game:GetService("RunService")
local Connections = {}
-- create connection and add to connections table
function AddConnection(Prompt : ProximityPrompt)
if Prompt then
table.insert(Connections, Prompt.Triggered:Connect(function()
Frame:TweenPosition(UDim2.new(0.441, 0, 0.18, 0.0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 2.5)
Value.Value = Value.Value + math.random(2, 16)
Text.Text = Value.Value
MoneySound:Play()
wait(4.5)
Frame:TweenPosition(UDim2.new(0.441, 0, -0.52, 0.0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 2.5)
end))
end
end
-- prevent memory leaks
function ClearConnections()
for _,Connection in ipairs(Connections) do
if Connection and typeof(Connection)=="RBXScriptConnection" and Connection.Connected then
Connection:Disconnect()
end
end
end
-- add current loaded Prompts
for i, v in pairs(CoinFolder:GetDescendants()) do
if v:IsA("ProximityPrompt") then
AddConnection(v)
end
end
--[[here comes the tricky part, after connecting all the loaded in instances,
it will now also connect newly loaded instances
]]
CoinFolder.DescendantAdded:Connect(function(AddedInstance)
if AddedInstance and AddedInstance:IsA("ProximityPrompt") then
AddConnection(AddedInstance)
end
end)
-- clear connections upon script getting destroyed
script.Destroying:Once(ClearConnections)
Edit : Fixed 2 triggers needed, trigger bug found and fixed by @mpc19801981
Try to put this at first lines of code:
if not game:IsLoaded() then
game.Loaded:Wait()
end
Thank you so much for the help although it makes me press it twice in order for it to work, it still works so I’ll work with that thank you all!
oh I didnt know it gets triggered twice, does this happen with all the prompts or only with the first one you want to trigger?
It happens with all of the prompts in the game
wait I think I misunderstand, do they get triggered twice or do you have to trigger them twice?
I have to trigger them twice for it to work
I think it’s because of double triggered event, I think @coolcostupit just didn’t notice.
Try to use this:
local Frame = script.Parent
local TS = game:GetService("TweenService")
local CoinFolder : Folder = game.Workspace:WaitForChild("Money", math.huge)
-- math.huge will force waitforchild to wait for ever instead of saying "infinite yield"
local Player = game:GetService("Players").LocalPlayer
local Value = Player.Character:WaitForChild("Purse")
local Text = script.Parent.TextLabel
local MoneySound = script.MoneySOund
local RunService = game:GetService("RunService")
local Connections = {}
-- create connection and add to connections table
function AddConnection(Prompt : ProximityPrompt)
if Prompt then
table.insert(Connections, Prompt.Triggered:Connect(function()
Frame:TweenPosition(UDim2.new(0.441, 0, 0.18, 0.0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 2.5)
Value.Value = Value.Value + math.random(2, 16)
Text.Text = Value.Value
MoneySound:Play()
wait(4.5)
Frame:TweenPosition(UDim2.new(0.441, 0, -0.52, 0.0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 2.5)
end))
end
end
-- prevent memory leaks
function ClearConnections()
for _,Connection in ipairs(Connections) do
if Connection and typeof(Connection)=="RBXScriptConnection" and Connection.Connected then
Connection:Disconnect()
end
end
end
-- add current loaded Prompts
for i, v in pairs(CoinFolder:GetDescendants()) do
if v:IsA("ProximityPrompt") then
AddConnection(v)
end
end
--[[here comes the tricky part, after connecting all the loaded in instances,
it will now also connect newly loaded instances
]]
CoinFolder.DescendantAdded:Connect(function(AddedInstance)
if AddedInstance and AddedInstance:IsA("ProximityPrompt") then
AddConnection(AddedInstance)
end
end)
-- clear connections upon script getting destroyed
script.Destroying:Once(ClearConnections)
Oh crap you’re right, I added 2 triggered connections instead of just 1 causing it to be needed to be triggered twice, my bad
Edit: I will apply this to the solution but I will mention you as you have fixed the triggered twice thingy
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.