Hi everyone,
I’m attempting to create a script where all players can see a light moving when the player moves their mouse. I started with a great script from this video:
However, I noticed that it was on a LocalScript, meaning no one else could see the light moving. Thus, I used a pair of Remote Events to try and connect the original modified script and a normal Script.
Edit: There are no errors in Output. When I equip the light, it doesn’t move.
Here’s the model if you want to see what’s wrong:
Flashlight.rbxm (30.9 KB)
Make sure to put it in StarterPack.
Layout:
Local Script
local cam = workspace.CurrentCamera
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Clone = script.Parent:WaitForChild("LightPart")
local light = script.Parent:WaitForChild("Light")
local move = script.Parent:WaitForChild("Move")
local Brightness = 10
local Keybind = Enum.KeyCode.F
local UIS = game:GetService("UserInputService")
local Toggle = false
local Mouse = game.Players.LocalPlayer:GetMouse()
UIS.InputBegan:Connect(function(Input, p)
if script.Parent.Equipped then
if p then return end
if Input.KeyCode == Keybind then
light:FireServer(Toggle)
Toggle = not Toggle
end
else
return
end
end)
script.Parent.Unequipped:Connect(function()
Toggle = false
end)
RunService.RenderStepped:Connect(function()
if Clone then
if not Toggle then
Clone.Position = cam.CFrame.Position
move:FireServer(Mouse.Hit.Position)
end
end
end)
Server Script
local light = script.Parent:WaitForChild("Light")
local move = script.Parent:WaitForChild("Move")
local Clone = script.Parent:WaitForChild("LightPart")
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.1, Enum.EasingStyle.Sine)
local Brightness = 10
move.OnServerEvent:Connect(function(p, pos)
TS:Create(Clone, TI, {CFrame = CFrame.lookAt(Clone.Position, pos)}):Play()
print(pos)
end)
light.OnServerEvent:Connect(function(p, bool)
if bool then
TS:Create(Clone.SpotLight, TI, {Brightness = Brightness}):Play()
else
TS:Create(Clone.SpotLight, TI, {Brightness = 0}):Play()
end
end)
Can anyone help? Anything is appreciated.
Thank you!