I made a gun that ejects shells in the server, and I want the local player to not be able to see the ejected shells in the server. I already made a script, but the problem is that it breaks because it doesn’t detect the ejected shell in workspace.
SCRIPT:
local part = workspace:WaitForChild(“BulletShell”)
local function modify(part)
part.Transparency = 1
end
If you are creating the part by a script and want a local script to wait until the part exists, then you should make the script fire a remote event and have the local script do RemoteEvent.OnClientEvent:Wait(). Nothing below that will run until the remote event is fired.
If this is a server script that’s waiting for a part which was created by the server, use a bindable event and any code under BindableEvent.Event:Wait() will not run until the event is fired.
If you didn’t know, to fire to a RemoteEvent to a client requires you to pass the argument of the player aka. client you want it to receive the event as the first parameter.
For getting the part in the localscript you should just send the part with the event.
Cool, so what you should do is create a RemoteEvent. Once the part is created on the server, have the server fire the event with RemoteEvent:FireClient(player)
Then, in the local script which detects the part, use RemoveEvent.OnClientEvent:Wait(). This will wait until the event is fired, so nothing under that line will run until the event is fired, AKA until the part is created
Nvm guys I figured it out. It didn’t have anything to do with remotes or that stuff. It was actually pretty simple. I just destroyed it instead of changed the transparency to 1
while true do
wait()
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == "P2000_mag" then
v:Destroy()
end
end
end```