i found this script in the toolbox and it works as intended, but i was wondering how to make it server-sided? i know how to use both remote events and functions but i completely clueless how to approach this lol
pls help
wait(1)
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local Character = Player.Character
local FlashlightOn = false
local FlashlightCamera = Instance.new("Part")
FlashlightCamera.Anchored = true
FlashlightCamera.Parent = Camera
FlashlightCamera.Transparency = 1
FlashlightCamera.Name = "FlashlightCamera"
FlashlightCamera.CanCollide = false
local FlashLIGHT = Instance.new("SpotLight")
FlashLIGHT.Parent = FlashlightCamera
FlashLIGHT.Enabled = false
FlashLIGHT.Range = 60
FlashLIGHT.Brightness = 2
local function ToggleFlashlight(input, prosecced)
if not FlashlightOn and not prosecced and input.KeyCode == Enum.KeyCode.F then
script.Sound:Play()
FlashLIGHT.Enabled = true
FlashlightOn = true
elseif FlashlightOn and not prosecced and input.KeyCode == Enum.KeyCode.F then
script.Sound:Play()
FlashLIGHT.Enabled = false
FlashlightOn = false
end
end
UserInputService.InputBegan:Connect(ToggleFlashlight)
Character:WaitForChild("Humanoid").Died:Connect(function()
FlashlightCamera:Destroy()
FlashLIGHT:Destroy()
end)
RunService.RenderStepped:Connect(function()
TweenService:Create(FlashlightCamera, TweenInfo.new(0.2), { CFrame = Camera.CFrame }):Play()
end)
If you wish the light to move server-side, I would highly recommend using networkownership. Your other option would be to fire a remote every renderstepped, which i don’t consider the most practical.
i’ve heard of network ownership but never implemented it before. from your post it states - you can only set unanchored part to have network ownership to the client, but I’m afraid my flashlight part can’t as it keeps phasing through the ground :,)
correct me if i’m wrong, but this was my attempt:
SERVER
function remoteFunctions.InsertLight.OnServerInvoke(plr)
local flashlight = replicated.Misc.Flashlight:Clone()
flashlight.Parent = plr.Character
flashlight:SetNetworkOwner(plr)
end
CLIENT
remoteFunctions.InsertLight:InvokeServer()
local flashlight = char:WaitForChild("Flashlight")
flashlight.Parent = cam
Yes, the implementation is correct, but the part phasing through the ground is an issue.
A part, that has it’s network owner as a player, can not be anchored. To overcome the issue of the part just falling through the ground, I would use bodymovers. For your usecase, AlignPosition and AlignOrientation might both be beneficial.
sorry :,) i’m not experienced enough to understand how bodymover works let alone implementing them. perhaps, you could show me some snippet? if not then it’s okay
It’s quite complex, but it’s worth learning it – I use them in almost all the games I make. Best you can do is either search about it or ask in another topic about them.