This script is meant to move a certain part, but it isn’t server sided.
local userInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local SpotlightHead = game.Workspace.Spotlight1.Arm
local UpdateCon
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.A then return end
if UpdateCon then
UpdateCon:Disconnect()
UpdateCon = nil
end
UpdateCon = RunService.Heartbeat:Connect(function(dt)
local newCFrame = SpotlightHead.PrimaryPart.CFrame * CFrame.Angles(0, -0.05, 0)
SpotlightHead:SetPrimaryPartCFrame(newCFrame)
end)
end)
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.A then return end
if not UpdateCon then return end
UpdateCon:Disconnect()
UpdateCon = nil
end)
Is there any way to implement RemoteEvents into this? (or make it so others can see movement in general)
Create an event inside of ReplicatedStorage and fire it whenever you start or stop holding the button. When the server receives the event it will toggle a value that’ll enable turning.
--// SERVER (SERVERSCRIPTSERVICE) //--
local REP = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")
local spotlightEvent = REP.SpotlightEvent
local SpotlightHead = game.Workspace.Spotlight1.Arm
local spotlightTurning
RS.Heartbeat:Connect(function()
if spotlightTurning then
local newCFrame = SpotlightHead.PrimaryPart.CFrame * CFrame.Angles(0, -0.05, 0)
SpotlightHead:SetPrimaryPartCFrame(newCFrame)
end
end)
spotlightEvent.OnServerEvent:Connect(function(plr, state)
spotlightTurning = state
end)
--// CLIENT (STARTERPLAYERSCRIPTS) //--
local REP = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local spotlightEvent = REP.SpotlightEvent
UIS.InputBegan:Connect(function(input, gp)
if gp then return end --// Prevent his from being executed when player is typing in chat.
if input.KeyCode == Enum.KeyCode.A then
spotlightEvent:FireServer(true)
end
end)
UIS.InputEnded:Connect(function(input, gp)
if gp then return end --// Prevent his from being executed when player is typing in chat.
if input.KeyCode == Enum.KeyCode.A then
spotlightEvent:FireServer(false)
end
end)
I fixed up parts to go to what I need (controlling a RobotArm’s specific parts)
--// CLIENT (STARTERPLAYERSCRIPTS) //--
local REP = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local remote = REP.FK1
UIS.InputBegan:Connect(function(input, gp)
if gp then return end --// Prevent his from being executed when player is typing in chat.
if input.KeyCode == Enum.KeyCode.G then
remote:FireServer(true)
end
end)
UIS.InputEnded:Connect(function(input, gp)
if gp then return end --// Prevent his from being executed when player is typing in chat.
if input.KeyCode == Enum.KeyCode.G then
remote:FireServer(false)
end
end)
--// SERVER (SERVERSCRIPTSERVICE) //--
local REP = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")
local remote = REP.FK1
local FrontKnuckle = game.Workspace.RobotArm.Knuckle
local Knuckles
RS.Heartbeat:Connect(function()
if Knuckles then
local newCFrame = FrontKnuckle.PrimaryPart.CFrame * CFrame.Angles(0, -0.05, 0)
FrontKnuckle:SetPrimaryPartCFrame(newCFrame)
end
end)
remote.OnServerEvent:Connect(function(plr, state)
Knuckles = state
end)
It doesn’t move the part though. (The scripts are placed in their respective spots, so is the RemoteEvent I added.)
[Actually, question, I’m not sure if MeshParts have a place to add a PrimaryPart, would I have to put it behind a model to do so?]
Could you share a screenshot of the hierarchy of the model? If the knuckle and finger part are separate you could use CFrame math to offset the rotation.
Just tested it for myself, realized that pivots run on a separate CFrame system:
RS.Heartbeat:Connect(function()
if Knuckles then
local x,y,z = FrontKnuckle:ToOrientation()
FrontKnuckle:PivotTo(FrontKnuckle:GetPivot() * CFrame.Angles(x, y - 0.05, z))
end
end)
See if this fix solves the second problem as well.
RS.Heartbeat:Connect(function()
if Knuckles then
local x,y,z = FrontKnuckle.CFrame:ToOrientation()
FrontKnuckle:PivotTo(FrontKnuckle:GetPivot()* CFrame.Angles(x, y - 0.05, z))
end
end)
It works now!
But for some reason even having it at 0.05 makes it extremely fast…
Slowing it down would require something like 0.000005, is there a way to fix that?
Something like (1 being really slow as a minimum)
Roblox uses two measurements for angles, radians and degrees.
x, y, z are in radians however 0.05 can be thought of as being in degrees.
we just need to convert 0.05 degrees to radians
the formula for that is: radians = degrees * pi/180°
0.05 deg = 0.000873 rad | Much smaller
However, Lua has a built-in function to do it for you: math.rad()
Anyways here’s the updated code:
RS.Heartbeat:Connect(function()
if Knuckles then
local x,y,z = FrontKnuckle.CFrame:ToOrientation()
FrontKnuckle:PivotTo(FrontKnuckle:GetPivot()* CFrame.Angles(x, y - math.rad(0.05), z))
end
end)