local mouse = game.Players.LocalPlayer:GetMouse()
function Light() local player = game.Players.LocalPlayer local playerChar = player.Character local playerLight = playerChar.Head:FindFirstChild("Light")
if playerLight then playerLight:Destroy() else local light = Instance.new("SurfaceLight",playerChar:FindFirstChild("Head")) light.Name = "Light" light.Range = 30 light.Angle = 50 light.Shadows = true light.Brightness = 2 end
end
mouse.KeyDown:connect(function(key)
key = key:lower() if key == "f" then Light() end
end)
this is a local script which i found off a tutorial (which i looked for these) but couldn't find the proper one also this is a keybind script not a tool so no tools i wanna make it so the whole server can see your flashlight when you use it need help
I have a solution to your problem: Remote Events
add a folder into ServerStorage, name it anything, then add a local script, remote event, and server script inside of the folder
I would advise naming the remote event LightEvent
In the local script type in:
local folder = script.Parent local player = game.Players.LocalPlayer local head = player.Character:WaitForChild("Head") local event = folder.LightEvent local userInputService = game:GetService("UserInputService") userInputService.InputBegan:Connect(function(key,isTyping) if isTyping == false then if key.KeyCode == Enum.KeyCode.F then event:FireServer() end end end)
and in the server script:
script.Parent.LightEvent.OnServerEvent:Connect(function(player, head) local playerLight = head:WaitForChild("Light") if playerLight then playerLight:Destroy() else local light = Instance.new("SurfaceLight", head) light.Name = "Light" light.Range = 30 light.Angle = 50 light.Shadows = true light.Brightness = 2 end end)
make sure to disable the local and server script
then, add a server script into ServerScriptService, inside of the script add:
local headLampFolder = game.ServerStorage.Name_of_folder_containing_serverscript+localscript+RemoteEvent game.Players.PlayerAdded:Connect(function(plr) local folderClone = headLampFolder:Clone() folderClone.Parent = plr folderclone.Name_of_server_script.Disabled = false folderclone.Name_of_local_script.Disabled = false end)
if you want to learn more about remote events heres a link