Hello! I’ve been trying to make a system where players can collect gifts and when they trigger a proximityPrompt, it converts the gifts in coins. It shouldnt be this hard but every time it returns 0 coins. This is my server script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local HousesFolder = workspace:WaitForChild("Game"):WaitForChild("Systems"):WaitForChild("Houses")
-- Remotes \\
local MessagesEvent = ReplicatedStorage.Remotes:WaitForChild("MessagesEvent")
local PlaceGiftEvent = ReplicatedStorage.Remotes:WaitForChild("PlaceGiftEvent")
local TriggerAnimEvent = ReplicatedStorage.Remotes:WaitForChild("TriggerAnimEvent")
local CameraShakeEvent = ReplicatedStorage.Remotes:WaitForChild("CameraShakeEvent")
-- //
local parentModel = script.Parent
local ChristmasTree = parentModel.Interior.Systems.ChristmasTree
local GiftsFolder = ChristmasTree:FindFirstChild("Gifts")
local function teleportPlayer(player, targetPart)
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
character:SetPrimaryPartCFrame(targetPart.CFrame)
print("Teleported " .. player.Name)
end
end
local function createLivesValue(player)
local lives = Instance.new("IntValue")
lives.Name = "Lives"
lives.Value = 3
lives.Parent = player
end
local function createPlacedGiftsValue(player)
local placedGifts = Instance.new("NumberValue")
placedGifts.Name = "PlacedGifts"
placedGifts.Value = 0
placedGifts.Parent = player
end
local function destroyLivesValue(player)
local lives = player:FindFirstChild("Lives")
if lives then
lives:Destroy()
end
end
local function shakeCamera(player)
CameraShakeEvent:FireClient(player)
end
local playerCooldowns = {}
local function onPlayerTouchDamagePart(player)
if playerCooldowns[player.UserId] then
return
end
local lives = player:FindFirstChild("Lives")
if lives and lives.Value > 0 then
local isLastLife = (lives.Value == 1)
if not isLastLife then
playerCooldowns[player.UserId] = true
end
lives.Value = lives.Value - 1
print(player.Name .. " lost a life. Lives left: " .. lives.Value)
shakeCamera(player)
if lives.Value <= 0 then
destroyLivesValue(player)
print(player.Name .. " has been teleported out due to 0 lives.")
TriggerAnimEvent:FireClient(player)
wait(1)
local teleporterPart = script.Parent.Teleporter
teleportPlayer(player, teleporterPart)
else
wait(2)
playerCooldowns[player.UserId] = nil
end
end
end
script.Parent:WaitForChild("Teleporter").ProximityPrompt.Triggered:Connect(function(player)
local placedGifts = player:FindFirstChild("PlacedGifts")
local playerBackpack = player:FindFirstChild("PlayerBackpack")
local giftCount = playerBackpack:FindFirstChild("GiftCount")
if not placedGifts then
createPlacedGiftsValue(player)
placedGifts = player:WaitForChild("PlacedGifts")
end
if giftCount and giftCount.Value > 0 then
local houseNumber = script.Parent.Name
local interiorModel = HousesFolder:FindFirstChild(houseNumber):FindFirstChild("Interior")
local spawnPart = interiorModel:FindFirstChild("SpawnPart")
local exitPart = interiorModel:FindFirstChild("ExitPart")
local teleportPart = script.Parent.Teleporter
if spawnPart then
TriggerAnimEvent:FireClient(player)
wait(1)
teleportPlayer(player, spawnPart)
if not player:FindFirstChild("Lives") then
createLivesValue(player)
end
local damagePartsFolder = interiorModel.Systems:FindFirstChild("DamageParts")
if damagePartsFolder then
for _, damagePart in ipairs(damagePartsFolder:GetDescendants()) do
if damagePart:IsA("BasePart") then
damagePart.Touched:Connect(function(hit)
local touchedPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if touchedPlayer and touchedPlayer == player then
onPlayerTouchDamagePart(player)
end
end)
end
end
end
end
exitPart.ProximityPrompt.Triggered:Connect(function()
local coins = player.leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = coins.Value + placedGifts.Value
print("Player will be rewarded with " .. placedGifts.Value .. " coins.")
end
TriggerAnimEvent:FireClient(player)
wait(1)
destroyLivesValue(player)
placedGifts:Destroy()
teleportPlayer(player, teleportPart)
end)
else
MessagesEvent:FireClient(player, "0GiftsMessage")
print(player.Name .. " has no gifts and cannot teleport.")
end
end)
ChristmasTree.PlacePart.ProximityPrompt.Triggered:Connect(function(player)
local houseNumber = script.Parent.Name
PlaceGiftEvent:FireClient(player, houseNumber)
end)
In my player, the placedGifts value is fine. Ive been stuck on this for like 1 1/2 hours, and i cant take it anymore, this was why i came here