Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part only moves to the mouse once?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

0
How can i do that? Instance_Brick 12 — 4y
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 User#28930 0 — 4y
0
but the off remote is to stop it Instance_Brick 12 — 4y
0
Fixed it thanks! Instance_Brick 12 — 4y
Ad

Answer this question