Hi,i want when i touched the part it fires remote event and a script will check if this part does it comply
with the conditions.
i wrote a basic script but it prints player name but i want it prints part name here is script:
this is a localscript inside character
wait(1)
local rs = game:GetService("ReplicatedStorage")
script.Parent.Hitbox.Touched:Connect(function(otherPart)
rs.RemoteEvent:FireServer(otherPart)
end)
----------
This is a script inside serverscriptservice
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("RemoteEvent")
re.OnServerEvent:Connect(function(part)
if part:WaitForChild("Attachment") then
print(part)
end
end)
RemoteEvents always pass in the player who fired the event as the first argument. So, on the server-sided code, you simply need to add a player argument before the âpartâ argument and your code should work.
-- Script in ServerScriptService
local rs = game:GetService("ReplicatedStorage")
local re = rs:WaitForChild("RemoteEvent")
re.OnServerEvent:Connect(function(player,part) -- player is always the first argument in remote events
if part:WaitForChild("Attachment") then
print(part)
end
end)
Ah, so it looks like the part youâre firing through the remote event is the wrong thing. Try firing otherPart.Parent from the client and I recommend using :FindFirstChild() instead of :WaitForChild() in this case as waiting for the child could cause an infinite yield if it does not exist.
Its because of Filtering Enabled the server cannot find or see parts created by the client even by firing a remote event it will never be able to find the part because as far as the server is concerned it is nil.
There is no solution to checking parts created by a client on the server the part is only visible to that client making it nil/doesnât exists for other clients and players, if you want to print the whole parts in workspace in a server script then use for i, v in pairs() do loop so in this instance it would be:
for i, v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
print(v.Name)
end
end