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

Sorry for all the questions, but the bottle STILL doesnt move!?

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

3 comments

1

The LocalScript must be inside the player somehow, such as putting it inside StarterGui or StarterPack.

2

LocalScripts will only run in the player's Backpack, Character, PlayerGui, PlayerScripts, and ReplicatedFirst.

0

If you need the script inside the player you can place the script in StarterCharacterScripts, doing this will insert the script into the character.

2 answers

  1. 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.

  2. 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)

  1. 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.

  2. 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!

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