How to make Apple respawner?

I have apples in the game that you can collect! When collecting part destroy. Is it possible to respawn in the same place with the scripts?

2 Likes

Yes. In the location where the Apple originally spawned, or where it was destroyed?

1 Like

Where it was destroyed, with scripts!

1 Like

Ok! So once it despawns, you’ll probably want to record its position, wait the respawn period, and then clone it. When you clone it, you can use Model:MoveTo and pass in the position you saved to respawn it there.

1 Like

Can you give the script if it’s not difficult ?

https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame

This method is safer I think.

I don’t really understand how it works

The DevForum isn’t really the right place to ask people to write code upon request. If you are trying to code it and others try to help you, that is encouraged. But if you want someone to script it for you, please hire someone for a commission. There are lots of talented scripters for hire out there. You can find Portfolios on the DevForum or the new Talent Hub if that’s what you are looking for.

Please take some attempt at scripting it, and then we will try to help. Otherwise, head over to the Talent Hub or find a portfolio you like, and you can find a scripter to help you out with the code for your game.

I see what you’re saying in that you can set it to the exact previous position and orientation regardless of collisions. I usually prefer MoveTo() sometimes because it will make sure it’s not colliding with anything. But, if it’s a non-moving object and collisions aren’t a concern, SetPrimaryCFrame is better. (I’m also assuming that you are not moving it a lot, because if you repeatedly use SetPrimaryCFrame, your model will eventually have precision issues and the parts will start to separate.)

I didn’t mean that you would write this to me, I meant to write an example and how it works

Ok, I see what you’re saying. It’s difficult for me to do that because the code for this would be relatively short. I thought of something you could do rather than destroying it that might be easier. I can write pseudo code though with some built in functionality:

local despawnDebounceTriggered = false

local apple = script.Parent

function appleTouched(part)
    if … and not despawnDebounceTriggered then -- the part that touched the apple is someone’s character and the apple is not currently despawned
        despawnDebounceTriggered = true
        -- Make it invisible
        -- Move the apple
        -- Apply effect to the player who touched it
        -- Wait some period of time
        -- Reposition the apple
        -- Make it visible
        despawnDebounceTriggered = false
    end
end
1 Like

I have ProximityPrompt on Part and it will be visible

If you move the object far away from the map, then you shouldn’t need to worry about the proximity prompt. Or, instead of moving it, you could just make the part/model invisible & non-collidable, and then disable the proximity prompt.

1 Like

Thank you very much! I’m already tired of looking for an answer

1 Like