Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

0
I believe it's because the tool I would just simply get a flashlight from the tool box TurkishBTW 2 — 3y
0
Its because its in a local script. Carlowskey 20 — 3y

1 answer

Log in to vote
0
Answered by
1JBird1 64
3 years ago
Edited 3 years ago

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

0
a question though, why do you want to destroy the light if there’s already a light? instead of returning? 1JBird1 64 — 3y
0
thats a tool not a keybind dylancrazy88 20 — 3y
0
oh its not in a tool, sorry about that, i’ll edit it a bit 1JBird1 64 — 3y
0
ok I’ve finished it, you can try it out now and see if it works. 1JBird1 64 — 3y
View all comments (2 more)
0
the script in server script service doesn't work because theres a red line underneath +localscript+RemoteEvent and yes i spelt everything right dylancrazy88 20 — 3y
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’. 1JBird1 64 — 3y
Ad

Answer this question