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

How to i pass instances through a remote event?

I am making a drag tool for filtering enabled, but i can't pass rays or instances (the part that i want to move) through a remote event. I managed to decompile the rays in to the six numbers, but i still cant grab the part.

before i separated the client and server, the grabber worked fine on solo mode, so the problem is with the remote events.

Here is my local script

function onMouseDown(mouse)
	if true then --ill change this to test for grab-able blocks later
		mouse.Icon ="rbxasset://textures\\GrabRotateCursor.png"
		part = mouse.Target
		local hitPoint = mouse.Hit:toObjectSpace(part.CFrame).p
		local instances = {part}
		script.Parent.Script.StartDrag:FireServer(part, hitPoint, instances)
	end
end

This is my Script

script.StartDrag.OnServerEvent:connect(function(mousePart, hitPoint, collection)
	if true then
		local part=mousePart
		dragger = Instance.new("Dragger")
		dragger:MouseDown(mousePart, hitPoint, collection)--This is line 8 where the error is from
		pcall(function()  end)
	end
end)

My error is

11:30:14.336 - Unable to cast value to Objects

11:30:14.337 - Script 'Players.Player1.Backpack.Drag.Script', Line 8

11:30:14.337 - Stack End

My question is how do i pass instance based variables like part IDs through remote events.

1 answer

✓ Accepted answer
script.StartDrag.OnServerEvent:connect(function(Player, Args)
    if true then

		local mousePart 		=	Args['mousePart'];
		local hitPoint			=	Args['hitPoint'];
		local collection			=	Args['collection'];
		
		print(mousePart, hitPoint);
		
		local part 				=	mousePart
       		local dragger 			=	Instance.new("Dragger")

        	dragger:MouseDown(mousePart, hitPoint, collection)
	
		pcall(function()  
		end)
    end
end)
function onMouseDown(mouse)
    if true then
        mouse.Icon 		=	 "rbxasset://textures\\GrabRotateCursor.png"
        local part 			=	 mouse.Target
        local hitPoint 		=	 mouse.Hit:toObjectSpace(part.CFrame).p
        local instances 		=	 {part}
	
		local Args = {['mousePart'] = part, ['hitPoint'] = hitPoint, ['collection'] = instances};

        game:GetService("ReplicatedStorage").StartDrag:FireServer(Args)
    end
end

2 comments

0

Well, i can now pass parts through remote events, but i still can't get the dragger to respond to them I think i know what to do now. Thanks

0

I got the dragger working compleatly, thanks :)

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