How to make a ProximityPrompt that gives you coins and destroys in Studio Lite💰
HTML-код
- Опубликовано: 10 фев 2025
- Script
local prompt = script.Parent -- The ProximityPrompt
local part = prompt.Parent -- The part that contains the ProximityPrompt
local coinsToGive = 10 -- Amount of coins to give
local respawnTime = 5 -- Time in seconds before the part respawns
-- Ensure the ProximityPrompt exists on the part
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function(player)
if not player or not player:IsA("Player") then return end
-- Find the leaderstats folder
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
-- Find the Coins value
local coins = leaderstats:FindFirstChild("Coins")
if coins and coins:IsA("IntValue") then
coins.Value = coins.Value + coinsToGive -- Add coins
print(player.Name .. " received " .. coinsToGive .. " coins. New balance: " .. coins.Value)
else
warn("Coins value missing or incorrect type for player: " .. player.Name)
end
else
warn("Leaderstats missing for player: " .. player.Name)
end
-- Ensure the part still exists before destroying
if part and part.Parent then
local partClone = part:Clone() -- Clone the part before destroying it
local parentFolder = part.Parent -- Store the parent reference
local partPosition = part.Position -- Store the original position
part:Destroy() -- Remove the part
task.wait(respawnTime) -- Wait for respawn time
-- Respawn the part
partClone.Parent = parentFolder
partClone.Position = partPosition
-- Ensure the ProximityPrompt still works
local newPrompt = partClone:FindFirstChild("ProximityPrompt")
if newPrompt then
newPrompt.Enabled = true -- Reactivate the ProximityPrompt
else
-- Create a new ProximityPrompt if it's missing
newPrompt = Instance.new("ProximityPrompt")
newPrompt.Parent = partClone
newPrompt.ActionText = "Collect Reward"
newPrompt.ObjectText = "Interact"
newPrompt.HoldDuration = 0 -- Instant trigger
end
end
end)
else
warn("No ProximityPrompt found on the part.")
end
TAGS
#robloxstudiolite #robloxtutorial #studiolite #roblox
Excellent 👌🏻
@@ShadowVortexOfficial Thanks