Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I find the part I touched in a server side script?

I have a localscript which fires a remoteevent when certain blocks are touched but I need to be able to know the specific block I touched on the server. Is this possible?

the localscript

local character = script.Parent 
local humanoid = character:WaitForChild("Humanoid")
local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("touchedEvent")

local debounce = false
local touched = humanoid.Touched:Connect(function(hit, limb)
	if debounce then
		return
	end
	
	-- if part not in object folder, return
	if hit.Parent ~= workspace.Objects then
		return
	end
	
	remote:FireServer() -- fires the server script when the object is touched
	
	debounce = true
	wait(0.2)
	debounce = false
end)

the server script (idk how to find the block I touched)

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("touchedEvent")

remote.OnServerEvent:Connect(function(player)
	
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	
	local headScale = humanoid:WaitForChild("HeadScale")
	local dScale = humanoid:WaitForChild("BodyDepthScale")
	local wScale = humanoid:WaitForChild("BodyWidthScale")
	local hScale = humanoid:WaitForChild("BodyHeightScale")
	
	
end)

1 answer

✓ Accepted answer

Just pass the part as an argument to your remote's :FireServer() method.

In local script, line 17:

remote:FireServer(hit) -- sends the touched part

In server script, line 4:

remote.OnServerEvent:Connect(function(player, part) -- the part touched gets stored in 'part'

From here you can reference the touched part from inside the server script by addressing the 'part' variable.

This discussion is preserved as it was. New answers, comments, and votes are closed.