How do I make a part get destroyed when a tool touches it. There is a local script inside the part that I want to be deleted, the code for it is:
script.Parent.Touched:Connect(function(hit) game.ReplicatedStorage.OpenMediumDoorEvent:FireServer(hit) end)
The remote event is inside ReplicatedStorage and the script that will handle the remote is in ServerScriptService, the code for that script is as follows:
game.ReplicatedStorage.OpenMediumDoorEvent.OnServerEvent:Connect(function(hit) if hit.Parent.Name == "MediumKey" then game.Workspace.Medium.MediumTeleport.PartToBeDeleted:Destoy() end end)
Hello.
Problems:
You used Destoy()
instead of Destroy()
.
The first parameter of OnServerEvent
is always the player who fired that event.
Solutions:
Use Destroy()
instead of Destoy()
.
Add the "player" parameter to the OnServerEvent
event.
Fixed ServerScript:
game.ReplicatedStorage.OpenMediumDoorEvent.OnServerEvent:Connect(function(player, hit) print("1") if hit.Parent.Name == "MediumKey" then print("Deleted") game.Workspace.Medium.MediumTeleport.PartToBeDeleted:Destroy() end end)
On line 3 you wrote Destoy()
instead of Destroy()
So change your server script to this
game.ReplicatedStorage.OpenMediumDoorEvent.OnServerEvent:Connect(function(hit) if hit.Parent.Name == "MediumKey" then game.Workspace.Medium.MediumTeleport.PartToBeDeleted:Destroy() end end)