How to Pass the mouse's position to the server?

i want the player to be able to make a cube follow the mouse pointer for a few sec… and then get destroyed!
i did it in a localscript and then realized others couldn’t see it…
so i made a RemoteEvent!
(actually 2 but ok…)
one for creating the part and one for moving it.
the creating RemoteEvent works fine but when it wants to move to the mouse
it says: “Unable To Cast CoordinateFrame To TweenInfo”
This is the code in the event script:

Move.OnServerEvent:Connect(function(plr,Object,Destination,Tweeninfo)
	local Service = game:GetService("TweenService")
	
	local tween = Service:Create(Object,Tweeninfo,{ CFrame = Destination})
	tween:Play()
	repeat wait() until tween.PlaybackState == Enum.PlaybackState.Completed
	return true
end)

and this is the code in the local script:

--Code Above This Code --------
local State = Move:FireServer(Part,Tweeninfo,Mouse.Hit)
---Code Below This Code

for some reason it doesn’t accept my information from the client…
Thanks In Advance!

[This only works if the part is unanchored]

You could try using AlignPosition instead of TweenService. Just adjust some variables and make the goal position the mouse’s position.

Because it is going from client to server, there may be some lag/late response to the mouse moving.

local AlignPos = Instance.new("AlignPosition")
AlignPos.Parent = Workspace
	AlignPos.Visible = false
	AlignPos.Attachment0 = Object
	AlignPos.Mode = Enum.PositionAlignmentMode.OneAttachment
	AlignPos.Position = Destination
	AlignPos.Enabled = true
	wait(5)

It Doesn’t Set The Attachment0.
Wanna Know why???
Because…
The annoying create function returns nil while also creating the part!!!
yes the create function returns the part it had created,
but the client Recieves NIL .
its still the same script from my first post so im not going to rewrite it here.
why?
Edit: Im dumb i didn’t post it there because i thought it was flawless so im just going to post it here

Create.OnServerEvent:Connect(function(plr,Size,Parent,Color,Position,Anchored,Name)
	local Part = Instance.new("Part")
	Part.Parent = Parent
	Part.Color = Color
	Part.Size = Size
	Part.Position = Position
	Part.Anchored = Anchored
	Part.Name = Name
	print(Part.Name)
	return Part
end)

You need to create an attachment and parent it under the part

All the newer constraints use attachments

1 Like

could you add print to both of those scripts?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.