I made a script for the flashlight on the client side but I’m having trouble moving it to the server. Can anyone help?
I wanted to make a server-side script to make the light visible to other players but my skills are a bit poor.
I tried to look at similar topics in the dev forum and found answers, but my attempts to transfer the script to the server side resulted in the script not working or doing something strange.
Here’s the code
local mouse = game.Players.LocalPlayer:GetMouse()
function Light()
local player = game.Players.LocalPlayer
local playerChar = player.Character
local playerLight = playerChar.HumanoidRootPart:FindFirstChild("Light")
local playerSound = playerChar.HumanoidRootPart:FindFirstChild("Sound")
if playerLight then
playerSound:Destroy()
playerLight:Destroy()
local play = Instance.new("Sound",playerChar:FindFirstChild("HumanoidRootPart"))
play.SoundId = "http://www.roblox.com/asset/?id=6020984334"
play:Play()
else
light = Instance.new("SpotLight",playerChar:FindFirstChild("HumanoidRootPart"))
light.Name = "Light"
light.Range = 30
light.Brightness = 1
light.Shadows = true
local play = Instance.new("Sound",playerChar:FindFirstChild("HumanoidRootPart"))
play.SoundId = "http://www.roblox.com/asset/?id=6020984334"
play:Play()
end
end
mouse.KeyDown:connect(function(key)
key = key:lower()
if key == "f" then
Light()
end
end)
In short, it adds SpotLight to the player’s body when the “F” key is pressed and also removes it when the “F” key is pressed again. It uses sound, but for now my goal is to translate the script itself and not the sound to the server side.