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

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

Asked by 8 years ago

This question already has an answer here:

Bottle does not leave ground? HELP NEEDED!
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

1
The LocalScript must be inside the player somehow, such as putting it inside StarterGui or StarterPack. Netflixy 126 — 8y
2
LocalScripts will only run in the player's Backpack, Character, PlayerGui, PlayerScripts, and ReplicatedFirst. MrLonely1221 701 — 8y
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. Michael_TheCreator 166 — 8y

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?

2 answers

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
8 years ago
Edited 8 years ago
  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

Ad
Log in to vote
0
Answered by 8 years ago

Thanks to all, I have altered the script using everyone's corrections and it finally works :D

Merry Christmas!