Ok, so, .Touched events cannot run on the client. How LocalScripts work is that it can access all the client things and things specific to the player (guis, camera, etc.). Basically, LocalScripts can only be run on the client, and should be used for client things. A .Touched event is not one of those. What you need are RemoteEvents. They are used for client- server and vice versa communication. For example, they're used for admin panels. You're going to need to do a little more work for something like this, but it's still super easy.
Here's the code, I guess. Remember to make a RemoteEvent in ReplicatedStorage called "DeleteChest"
Server Script(put this in the chest. if it's a collection of parts, just tell me and I'll fix it.)
local chest = script.Parent
local debounce = false
local debounceTime = 1
function onTouched(hit)
if not debounce then
debounce = true
if hit.Parent then
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
print("someone has touched the chest!")
local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
game.ReplicatedStorage.DeleteChest:FireClient(plr, chest)
wait(debounceTime)
else
print("touched something that wasnt a person")
end
debounce = false
end
else
warn("tried to run but debounce exisited")
end
end
chest.Touched:Connect(function(hit)
print("touched")
onTouched(hit)
end)
Local Script (put this in StarterPlayerScripts)
local plr = game.Players.LocalPlayer
game.ReplicatedStorage.DeleteChest.OnClientEvent:Connect(function(chest)
chest.Transparency = 1
wait(1)
chest:Destroy()
end)
pls accept the answer if it worked
4 comments
Maybe using a remote event server to client
The debouncer can be a bool value, it doesn't have to be a number.
Also, why are you adding local to chest.Transparency?
Why did you add local to chest.Transparency and chest:Destroy()? Remove the local