#hey i got an problem i am trying to make an super market simulator and i have an pc that you can buy

39 messages · Page 1 of 1 (latest)

wide helm
#
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local money = leaderstats:WaitForChild("Money")

local function onClick()
    print("Button clicked!")
    print("Money before purchase:", money.Value)
    if money.Value >= 11 then
        money.Value = money.Value - 11
        local boxSpawner = game.Workspace:FindFirstChild("BoxSpawner")
        if boxSpawner then
            local waterBoxModel = game.Workspace:FindFirstChild("WaterBoxModel")
            if waterBoxModel then
                local primaryPart = waterBoxModel.PrimaryPart
                if primaryPart then
                    waterBoxModel:SetPrimaryPartCFrame(boxSpawner.CFrame)
                else
                    warn("PrimaryPart not found in WaterBoxModel.")
                end
            else
                warn("WaterBoxModel not found in Workspace.")
            end
        else
            warn("BoxSpawner not found in Workspace.")
        end
    else
        print("Not enough money to buy the water box!")
    end
end

buyButton.MouseButton1Click:Connect(onClick)```
pastel minnow
#

whats the issue

wide helm
#

When i buy the water it does not give me the box

#

Its supposed to teleport to the part

#

@pastel minnow

pastel minnow
#

because iirc you destroy the box, right?

wide helm
#

Ok

#

I will try that in a few minutes

#
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local money = leaderstats:WaitForChild("Money")

local function onClick()
    print("Button clicked!")
    print("Money before purchase:", money.Value)
    if money.Value >= 11 then
        money.Value = money.Value - 11
        
        local boxSpawner = game.Workspace:FindFirstChild("BoxSpawner")
        if boxSpawner then
            local replicatedStorage = game:GetService("ReplicatedStorage")
            local waterBoxModel = replicatedStorage:FindFirstChild("WaterBoxModel")
            
            if waterBoxModel then
                local primaryPart = waterBoxModel.PrimaryPart
                if primaryPart then
                    local newBox = waterBoxModel:Clone()
                    newBox.Parent = game.Workspace
                    newBox:SetPrimaryPartCFrame(boxSpawner.CFrame)
                    print("Water box spawned at BoxSpawner location.")
                else
                    warn("PrimaryPart not found in WaterBoxModel.")
                end
            else
                warn("WaterBoxModel not found in ReplicatedStorage.")
            end
        else
            warn("BoxSpawner not found in Workspace.")
        end
    else
        print("Not enough money to buy the water box!")
    end
end

buyButton.MouseButton1Click:Connect(onClick)
``` like this?
#

it works kinda

#

the thing is the box has no functions now

#

like i can t carry and open it no more

#

@pastel minnow

pastel minnow
#

how are you handling that behavior

wide helm
#
local prompt = script.Parent
local animation = script.Animation

local distanceZ = -2.7
local distanceY = -0.5

local animationTrack = nil
local owner = nil

local UserInputService = game:GetService("UserInputService")

prompt.Triggered:Connect(function(player)
    local character = player.Character
    local humanoid = character:FindFirstChild("Humanoid")

    if not animationTrack then
        animationTrack = humanoid:LoadAnimation(animation)
    end

    if not model:FindFirstChildWhichIsA("WeldConstraint") and owner == nil and not player:FindFirstChild("Carry") then
        local CarryValue = Instance.new("BoolValue", player)
        CarryValue.Name = "Carry"

        local weld = Instance.new("WeldConstraint", model)
        model.CanCollide = false
        model.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, distanceY, distanceZ)
        weld.Part0 = model
        weld.Part1 = character.HumanoidRootPart
        owner = player.Name
        animationTrack:Play()
    elseif model:FindFirstChildWhichIsA("WeldConstraint") and owner == player.Name and animationTrack and player:FindFirstChild("Carry") then
        animationTrack:Stop()
        model:FindFirstChildWhichIsA("WeldConstraint"):Destroy()
        player:FindFirstChild("Carry"):Destroy()
        model.CanCollide = true
        owner = nil
        animationTrack = nil
    end

    humanoid.Died:Connect(function()
        pcall(function()
            player.Carry:Destroy()
        end)
    end)
end)

-- Keyboard input handling
UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.F then
        if owner ~= nil then
            model:Destroy()
        end
    end
end)```
#

this is the carry one

#

yeah

#

@pastel minnow

pastel minnow
# wide helm

not sure why they're breaking, but I recommend using collectionService for handling the boxes instead of a bunch of scripts per box

#

that might fix it

#

wait

#

are you cloning the boxes locally?

#

because server scripts dont run if you clone them on the client

#

so you should either set the runContext on each script to client

#

or use collectionService

wide helm
#

lemme try

#

like add WaterBox1 - WaterBox2 - WaterBox3?

#

@pastel minnow

pastel minnow
#

just change the box script's runcontext to client and see what happens

wide helm
#

thanks

#

@pastel minnow

#

now it works