You can write your topic however you want, but you need to answer these questions:
Hi, i want to make a part the goes up when a button is pressed. But the part does not go up.
local redPart = game.Workspace.R
UIS = game:GetService("UserInputService")
local function onInputbegan(input, gameProcessed)
if input.UserinputType == Enum.UserInputType.MouseButton3 then
for count = 1,10 do
wait()
redPart.CFrame = CFrame.new(redPart.Position) + Vector3.new(0,1,0)
end
end
end
``
Can someone help me with this simple problem.
You can try modifying the velocity instead, also it doesn’t seem you’re like you’re using input correctly.
-- Services
local UserInputService = game:GetService("UserInputService")
-- Reference
local redPart = workspace:WaitForChild("R")
local function onInputBegan(inputObject, gameProcessed)
if gameProcessed then return end
local key = inputObject.KeyCode
if inputObject.UserInputType == Enum.UserInputType.MouseButton3 then
redPart.AssemblyLinearVelocity = Vector3.new(0, 1, 0)
end
end
UserInputService.InputBegan:Connect(onInputBegan)
This does not work because you’re not calling the function. I’d suggest using TweenService to tween it smoothly instead of a loop. If you want this to be seen by everyone, consider using a RemoteEvent.
-- Services
local UserInputService = game:GetService("UserInputService")
-- Reference
local redPart = workspace:WaitForChild("R")
local function onInputBegan(inputObject, gameProcessed)
if gameProcessed then return end
local key = inputObject.KeyCode
if inputObject.UserInputType == Enum.UserInputType.MouseButton3 then
redPart.AssemblyLinearVelocity = Vector3.new(0, redPart:GetMass() * workspace.Gravity, 0)
end
end
UserInputService.InputBegan:Connect(onInputBegan)
Having the key there doesn’t hurt. It’s for future purposes if you actually want to get the key easier. Though removing it won’t hurt either.
@younis2811 So I was testing it out a bit to see why it wasn’t working. It only works if you have network ownership over the part. For now I opted to create the object on the client.
-- Services
local UserInputService = game:GetService("UserInputService")
-- Reference
local redPart = Instance.new("Part")
redPart.Name = "R"
redPart.CFrame = CFrame.new(5.953, 79.223, 16.937)
redPart.Parent = workspace
local function onInputBegan(inputObject, gameProcessed)
if gameProcessed then return end
local key = inputObject.KeyCode
if inputObject.UserInputType == Enum.UserInputType.MouseButton3 then
print("Working")
redPart.AssemblyLinearVelocity = Vector3.new(0, redPart:GetMass() * workspace.Gravity/60, 0)
end
end
UserInputService.InputBegan:Connect(onInputBegan)
Edit: You might want to adjust the CFrame as your environment may be different from mine.