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

Part only moves to the mouse once?

Ok so ive got a script so when u hold down q it would make a beam depending on where your mouse cursor is but i have a problem it only moves the mouse once then stops and doesnt move again how can i fix this?

local on = false
script.Remotes.On.OnServerEvent:Connect(function(plr,mouse)
	on = true
	local folder = Instance.new("Folder",workspace.Beams)
	folder.Name = plr.Name
	local endpart = Instance.new("Part",folder)
	endpart.Size = Vector3.new(0.99, 0.99, 0.99)
	endpart.Anchored = true
	local beam = script.Stuff.Beam:Clone()
	beam.Parent = plr.Character.LeftHand
	local att1 = Instance.new("Attachment",plr.Character.LeftHand)
	local att2 = Instance.new("Attachment",endpart)
	beam.Attachment0 = att1
	beam.Attachment1 = att2

	while on == true do
		local posx,posy,posz = mouse.X,mouse.Y,mouse.Z
		endpart.Position = Vector3.new(posx,posy,posz)
		wait()
	end
end)

script.Remotes.Off.OnServerEvent:Connect(function(plr)
	workspace.Beams[plr.Name]:Destroy()
	on = false
	plr.Character.LeftHand.Beam:Destroy()
	plr.Character.LeftHand.Attachment:Destroy()
end)

1 answer

✓ Accepted answer

The argument mouse that you pass through the event will not change unless you change it inside of the function. The changes you make to it on the client do not replicate over to the variable on the server; they are not connected in any way. So it is always the same value no matter what.

Basically meaning your local posx,posy,posz = mouse.X,mouse.Y,mouse.Z will always result in the same thing.

You need to find a way to update the value that it should change its position to.

4 comments

0

How can i do that?

0

The best way I can think of right now would be to create the beam before they want to move it and then instead of an on and off remote, have a remote that only changes the position of the beam

0

but the off remote is to stop it

0

Fixed it thanks!

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