#Item in workspace is not being deleted

1 messages · Page 1 of 1 (latest)

frigid pier
#

So basically

When a selected player presses "g" ; they a cheeseblock is confirmed/placed, and I want it so at the eend of hte game ; in server-wide script ; I find in workspace "FinalCheese" and destroy it but its not working

local function confirmCheesePlacement()
if cheesePlaced and lastPlacedBlock then
lastPlacedBlock.Name = "FinalCheese"

    local detector = Instance.new("ClickDetector")
    detector.MaxActivationDistance = 32
    detector.Parent = lastPlacedBlock

    detector.MouseClick:Connect(function(playerWhoClicked)
        local name = playerWhoClicked.Name
        print(name .. " found the cheese!")
        
    
        Winner:FireServer(name)
    end)

    
    if Tool.Parent == Player.Character or Tool.Parent == Player.Backpack then
        tool:Destroy()
        ConfirmPlacementEvent:FireServer()
    end

    if previewBlock then
        previewBlock:Destroy()
        previewBlock = nil
    end

    print("Cheese block placement confirmed by player!")
else
    
    PlaceGui.Enabled = true
    delay(2, function()
        PlaceGui.Enabled = false
    end)
end

end

^^ Tool Script

        print("Scanning for FinalCheese...")

        for _, obj in ipairs(workspace:GetDescendants()) do
            if obj:IsA("BasePart") and obj.Name == "FinalCheese" then
                print("[RoundManager] Destroying FinalCheese block at:", obj:GetFullName())
                obj:Destroy()
                break
            end
        end

        end

^^ Serverwide Script

The server can't find the "FinalCheese" and destroy it

frigid pier
#

Ok I need serious help

#

local function confirmCheesePlacement()
if cheesePlaced and lastPlacedBlock then
lastPlacedBlock.Name = "FinalCheese"
lastPlacedBlock.Parent = workspace

I put the block into workspace but the thing can't fidn it

#

Since the script where teh block is placed in workspace is from a local script

#

is taht why it can't be found?

#

I've tried so many times and hasn't worked

rocky venture
#

What is the script has the confirmCheesePlacement function?

frigid pier
# rocky venture What is the script has the `confirmCheesePlacement` function?

Gbutton.MouseButton1Click:Connect(function()
if isEquipped then confirmCheesePlacement() end
end)

&

if renderSteppedConnection then renderSteppedConnection:Disconnect() end
renderSteppedConnection = RunService.RenderStepped:Connect(updatePreviewPosition)

if inputBeganConnection then inputBeganConnection:Disconnect() end
inputBeganConnection = UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed or not isEquipped then return end

    if input.KeyCode == Enum.KeyCode.R then
        rotateY()
    elseif input.KeyCode == Enum.KeyCode.T then
        rotateX()
    elseif input.KeyCode == Enum.KeyCode.P then
        placeBlock()
    elseif input.KeyCode == Enum.KeyCode.G then
        confirmCheesePlacement()
    end
end)

updatePreviewPosition()    

end)

#

Glad you can help

rocky venture
#

So this script is a LocalScript, right?

frigid pier
rocky venture
#

LocalScripts are Local

frigid pier
#

ye

rocky venture
#

If you make a part appear locally, server wont see it

frigid pier
#

Ye but how do I make it appear for whole server

chrome radishBOT
#

studio** You are now Level 4! **studio

rocky venture
#

You use RemoteEvent

frigid pier
#

and then

rocky venture
#

RemoteEvent is used for client-server communication

#

You can use a RemoteEvent to ask the server to spawn a part

frigid pier
#

ye but once the remote event is fired how do i make the part appear for the server in workspace

rocky venture
#

First, you create the RemoteEvent

frigid pier
#

k done

rocky venture
#

Second, you use RemoteEvent:FireServer() in your LocalScript where the confirmCheesePlacement() was

frigid pier
#

its called "WorkspaceCheese"

rocky venture
#

You have to put the RemoteEvent in ReplicatedStorage

#

And when all that is set-up, you have to create a (Server)Script

#

That receive the RemoteEvent:Fire

rocky venture
#

You have to use RemoteEvent.OnServerEvent:Connect()

frigid pier
#

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local WorkspaceCheese = ReplicatedStorage:WaitForChild("WorkspaceCheese")

WorkspaceCheese.OnClientEvent:Connect(function()

end)

rocky venture
#

OnServerEvent

#

Not OnClientEvent

frigid pier
#

done

#

WorkspaceCheese.OnServerEvent:Connect(function()

rocky venture
#

Then you do the spawn part thing in the function() end

frigid pier
#

what?

#

what part do I spawn

#

oh wait

#

nah i dont understand

rocky venture
#

The thing you were making locally

#

This thing:
local function confirmCheesePlacement()

frigid pier
#

oh

#

so do I copy and paste?

rocky venture
#

And you change the paths

frigid pier
rocky venture
#

You set up lastPlacedBlock

frigid pier
#

thats going to take long oof

rocky venture
#

Ok, wait

chrome radishBOT
#

studio** You are now Level 8! **studio

rocky venture
#

I'm opening Studio

frigid pier
#

cuz everything wraps around each thing if you know what I mean

#

If I name lastPlacedBlock , I gotta name everything before that as well

#

@rocky venture

rocky venture
#

Client:

local RemoteEvent: RemoteEvent = game.ReplicatedStorage.RemoteEvent

local function confirmCheesePlacement()
    if cheesePlaced and lastPlacedBlock then
        RemoteEvent:FireServer(lastPlacedBlock)
        
        local detector = Instance.new("ClickDetector")
        detector.MaxActivationDistance = 32
        detector.Parent = lastPlacedBlock

        detector.MouseClick:Connect(function(playerWhoClicked)
            local name = playerWhoClicked.Name
            print(name .. " found the cheese!")


            Winner:FireServer(name)
        end)


        if Tool.Parent == Player.Character or Tool.Parent == Player.Backpack then
            tool:Destroy()
            ConfirmPlacementEvent:FireServer()
        end

        if previewBlock then
            previewBlock:Destroy()
            previewBlock = nil
        end

        print("Cheese block placement confirmed by player!")
    else

        PlaceGui.Enabled = true
        delay(2, function()
            PlaceGui.Enabled = false
        end)
    end
end

Server:

local RemoteEvent: RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(Player, Part: BasePart)
    Part.Name = "FinalCheese"
    Part.Parent = game.Workspace
end)
frigid pier
#

lets see

#

ServerScriptService.ServerScriptService.CheeseScript:11: attempt to index nil with 'Name' @rocky venture

rocky venture
#

You need to change your confirmCheesePlacement function by the one I sent

#

And also you can put everything else back to like it was before

#

Only do the last thing I sent

#

That should work

frigid pier
#

@rocky venture didnt work

rocky venture
#

Send me your code at current state

frigid pier
#

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local WorkspaceCheese = ReplicatedStorage:WaitForChild("WorkspaceCheese")
local lastPlacedBlock = nil
local previewBlock = nil

WorkspaceCheese.OnServerEvent:Connect(function(Player, Part: BasePart)
Part.Name = "FinalCheese"
Part.Parent = game.Workspace
end)

#

local function confirmCheesePlacement()
if cheesePlaced and lastPlacedBlock then
WorkspaceCheese:FireServer()

        local detector = Instance.new("ClickDetector")
        detector.MaxActivationDistance = 32
        detector.Parent = lastPlacedBlock

        detector.MouseClick:Connect(function(playerWhoClicked)
            local name = playerWhoClicked.Name
            print(name .. " found the cheese!")


            Winner:FireServer(name)
        end)


        if Tool.Parent == Player.Character or Tool.Parent == Player.Backpack then
            tool:Destroy()
            ConfirmPlacementEvent:FireServer()
        end

        if previewBlock then
            previewBlock:Destroy()
            previewBlock = nil
        end

        print("Cheese block placement confirmed by player!")
    else

        PlaceGui.Enabled = true
        delay(2, function()
            PlaceGui.Enabled = false
        end)
    end
end
#

how do you do the black background thing

rocky venture
#

`

#

x3

#

Not '

#

`

#

Bellow Escape

frigid pier
#
        if cheesePlaced and lastPlacedBlock then
        WorkspaceCheese:FireServer()

            local detector = Instance.new("ClickDetector")
            detector.MaxActivationDistance = 32
            detector.Parent = lastPlacedBlock

            detector.MouseClick:Connect(function(playerWhoClicked)
                local name = playerWhoClicked.Name
                print(name .. " found the cheese!")


                Winner:FireServer(name)
            end)


            if Tool.Parent == Player.Character or Tool.Parent == Player.Backpack then
                tool:Destroy()
                ConfirmPlacementEvent:FireServer()
            end

            if previewBlock then
                previewBlock:Destroy()
                previewBlock = nil
            end

            print("Cheese block placement confirmed by player!")
        else

            PlaceGui.Enabled = true
            delay(2, function()
                PlaceGui.Enabled = false
            end)
        end
    end
    ```
rocky venture
#

:)

frigid pier
#
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local WorkspaceCheese = ReplicatedStorage:WaitForChild("WorkspaceCheese")
local lastPlacedBlock = nil
local previewBlock = nil

WorkspaceCheese.OnServerEvent:Connect(function(Player, Part: BasePart)
    Part.Name = "FinalCheese"
    Part.Parent = game.Workspace
end) 
rocky venture
frigid pier
#

still nope

rocky venture
#

You did this?:

frigid pier
#

yee

rocky venture
#

Bru

frigid pier
#

local function confirmCheesePlacement()
if cheesePlaced and lastPlacedBlock then
WorkspaceCheese:FireServer(lastPlacedBlock)

rocky venture
#

Send again all

#

I'll take a deep look

frigid pier
#

should we go to dms

rocky venture
#

If you want

frigid pier
#

like ill send you the whole thing

#

actually i;ll send you the whole thing here

#

its 300 lines so i hope you don't mind

rocky venture
#

I don't

frigid pier
#

nvm i cant even send cuz of hte limit

rocky venture
#

You can as a TXT file

#

Just press send button

frigid pier
#
local function confirmCheesePlacement()
        if cheesePlaced and lastPlacedBlock then
        WorkspaceCheese:FireServer(lastPlacedBlock)

            local detector = Instance.new("ClickDetector")
            detector.MaxActivationDistance = 32
            detector.Parent = lastPlacedBlock

            detector.MouseClick:Connect(function(playerWhoClicked)
                local name = playerWhoClicked.Name
                print(name .. " found the cheese!")


                Winner:FireServer(name)
            end)

    
            if Tool.Parent == Player.Character or Tool.Parent == Player.Backpack then
                tool:Destroy()
                ConfirmPlacementEvent:FireServer()
            end

            if previewBlock then
                previewBlock:Destroy()
                previewBlock = nil
            end

            print("Cheese block placement confirmed by player!")
        else

            PlaceGui.Enabled = true
            delay(2, function()
                PlaceGui.Enabled = false
            end)
        end
    end

rocky venture
#

You can't do this?

frigid pier
#

thanks fo your help

chrome radishBOT
#

studio** You are now Level 5! **studio

rocky venture
#

Um

#

I don't get why it does not work

#

The part doesn't get parented to the Workspace at all?

frigid pier
#

@rocky venture

#

I've worked on it

#

and im almost thing

#

but not there yet

#

ye i need hlep.

rocky venture
#

What you need help for?

#

It shouldn't be that hard D:

frigid pier
#

but when the round ends the cheese is not destroyed thats wht

#

@rocky venture

#

I've gotten it to work

#

but just one thing

#
    
    finalBlock.Name = "FinalCheese_" .. player.Name
    finalBlock.CFrame = cheeseCFrame
    finalBlock.Anchored = true
    finalBlock.CanCollide = true
    finalBlock.Transparency = 0
    finalBlock.Parent = workspace
    
    local detector = Instance.new("ClickDetector", finalBlock)
    detector.MouseClick:Connect(function(p)
        print(p.Name .. " clicked the cheese!")
        finalBlock:Destroy()
    end)
end)

CleanupFinalCheese.OnServerEvent:Connect(function()
    finalBlock:Destroy()
end)
#

CleanupFinalCheese:FireAllClients()

#

It didn't destroy the finalblock..

#

so what happens is ; i confirm the block, round ends (it should be destroyed but isnt) ; then I rejoin the round, block is still there, I click it, then finally it is destroyed

#

this shouldn't be happening

rocky venture
#

ClickDetector isn't working?

#

I don't see why you FireAllClients

chrome radishBOT
#

studio** You are now Level 9! **studio

frigid pier
#

ok now everything stuffed

rocky venture
#

I don't get how you cannot manage to destroy a part

frigid pier
#

now when i press "g" it automatically deletes the block without the round ending

rocky venture
#

Just :Destroy() it

frigid pier
#

wait 1 sec here

#
        if hiderPlayer and hiderPlayer.Name then
            status.Value = hiderPlayer.Name .. " has won the game!"
        
            CleanupFinalCheese:FireAllClients() 




            print("[Round] " .. hiderPlayer.Name .. " wins because time ran out.")
        else
            status.Value = "Hider wins!"
        end
    end

    wait(2)
    status.Value = "Match Over."
    wait(2)
    ```
#

see

#

I fired the cleanupFinalCheese

#

see

#
        finalBlock:Destroy()
    end)
end)
#

it should destroy the block shouldn't it? but no it doesn't

rocky venture
#

CleanupFinalCheese:FireServer()

#

not

#

CleanupFinalCheese:FireAllClients()

frigid pier
frigid pier
#

@rocky venture

#

i solved it.

#

its because it was firing a remote event

#

not binadble

#

bindable

rocky venture
#

Ok nice