Because you destroy it when it’s equal to 15?
But ive said when it gets triggered its going to get destroyed
youre checking if your coins equal 15 so when you have more it wont work, replace the ==
with >=
to check if the coins are more than or equal to 15
That doesnt seem the case, ive just tried it, unable to work
oh yeah just figured out your while true do loop is stopping the proximityprompt code, copy the whole while true do
part and the lines below it and paste them under the proximityprompt code
this was what you were saying for the script
The other way, paste the Trigged Event in the while true loop
I would handle the while loop in a different script, as you can never escape a while loop. That is, of course, if you don’t use a break. But in your case, a break seems unnecessary.
Edit: You could also use coolyoshi’s method, as that would be a little more efficient.
game.Workspace.hi.ProximityPrompt.Triggered:Connect(function(hit)
end)
while true do
end
like this
if i put it in a different script how would i get that to work
This is how I would do it:
game.Players.PlayerAdded:Connect(function(player)
while true do
task.wait(1)
player.leaderstats.coins.Value += 1
end
end)
Edit: Again, I highly recommend you use yoshi’s method with task.spawn, as I would say that is more script-efficient
Here task.spawn might help you, just replace this with the while true loop and triggered event.
task.spawn(function()
while true do
wait(1)
coins.Value = coins.Value + 1
end
end)
game.Workspace:WaitForChild("hi").ProximityPrompt.Triggered:Connect(function()
if coins.Value >= 15 then
workspace.hi.Transparency = 1
workspace.hi.ProximityPrompt:Destroy()
end
end)
I didn’t even think of that! I forgot that task.spawn allows code below it to run even while the function is running!
Oh my, I just found the problem! YOU HAVE TO SAY game.Workspace NOT JUST workspace
You need to put the while true loop under the ProximityPrompt Triggered event.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
coins.Value = 0
game.Workspace.hi.ProximityPrompt.Triggered:Connect(function(hit)
if coins.Value >= 15 then
workspace.hi.Transparency = 1
workspace.hi.ProximityPrompt:Destroy()
end
end)
while true do
task.wait(1)
coins.Value += 1
end
end)
Nope! You can totally say workspace
instead of game.Workspace
. The only difference is organization and how they look. I have linked a post below that explains the difference.