ply = game.Players.LocalPlayer mouse = ply:GetMouse() go = false Part = script.Parent --creates function function Up() game.Workspace.Part.Anchored = true game.Workspace.Part.CFrame = game.Workspace.Part.CFrame + CFrame.new(0,0.3,0) end --creates loop while true do mouse.Button1Down:connect(function() go = true end) mouse.Button1Up:connect(function() go = false game.Workspace.Part.Anchored = false end) if go == true then Up() else game.Workspace.Part.Anchored = false end wait(0.1) end
No errors are popping up, its just that the bottle doesnt move upwards when the mouse is held down I cant figure out why.
The code is in a local script inside of the waterbottle part
Make sure it is a working local script. LocalScripts only run inside a player or a character. If you do move the script, make sure to change the "Part" variable.
game.Workspace.Part.CFrame = game.Workspace.Part.CFrame + CFrame.new(0,0.3,0)
, you are not allowed to add CFrames. Add a vector3 like so.
game.Workspace.Part.CFrame = game.Workspace.Part.CFrame + Vector3.new(0,0.3,0)
You defined Part at the start, but never used that variable in the script. Maybe it is working but it moves a different part than you want.
It should work, but note you shouldn't have your mouse connections inside the loop. That probably creates a ton of functions over time.
Here is a revised version:
ply = game.Players.LocalPlayer mouse = ply:GetMouse() go = false Part = script.Parent --move part function Up() Part.Anchored = true Part.CFrame = Part.CFrame + Vector3.new(0,.3,0) end --mouse input mouse.Button1Down:connect(function() go = true end) mouse.Button1Up:connect(function() go = false Part.Anchored = false end) --loop while wait(0.1) do if go then Up() else Part.Anchored = false end end
Thanks to all, I have altered the script using everyone's corrections and it finally works :D
Merry Christmas!
Marked as Duplicate by MrLonely1221, SimplyRekt, and TheeDeathCaster
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?