Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make it so the whole server can see your flashlight?

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

2 comments

0

I believe it's because the tool I would just simply get a flashlight from the tool box

0

Its because its in a local script.

1 answer

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

6 comments

0

a question though, why do you want to destroy the light if there’s already a light? instead of returning?

0

thats a tool not a keybind

0

oh its not in a tool, sorry about that, i’ll edit it a bit

0

ok I’ve finished it, you can try it out now and see if it works.

0

the script in server script service doesn't work because theres a red line underneath +localscript+RemoteEvent and yes i spelt everything right

0

I didn’t mean for you to actually type down ‘Name_of_folder_containing_serverscript+localscript+RemoteEvent’, you were supposed to name it yourself, like ‘headLampFolder’.

This discussion is preserved as it was. New answers, comments, and votes are closed.