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

I have a local press F for flaslight system. But how can I make it serverside?

Asked by 3 years ago

So, I have this script located in StarterGui, that whenever you press F it will create a light that acts like a flashlight, inside the RootPart of the player. When you press F again it will dissapear. However, you can only see it on your client. How can I make it serverside?

local inputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local player = game.Players.LocalPlayer 
local character = player.Character or player.CharacterAdded:Wait() 
local enabled = false 
local light 

inputService.InputBegan:Connect(function(Input) 
    if Input.KeyCode == Enum.KeyCode.F then 
        if not enabled then 
            light = Instance.new("PointLight", character.HumanoidRootPart)
            light.Brightness = 2
            light.Name = "TorsoLight" 
            light.Range = 0 
            light.Shadows = true 
            tweenService:Create(light, tweenInfo, {Range = 25}):Play() 
            game.Workspace.SoundEffects.FlashlightOn:Play()
            enabled = true 
        else 
            tweenService:Create(light, tweenInfo, {Range = 0}):Play() 
            game.Workspace.SoundEffects.FlashlightOff:Play()
            wait(0.70) 
            light:Destroy()
            enabled = false 
        end
    end
end)

1 answer

Log in to vote
0
Answered by
kjljixx 42
3 years ago

You can use RemoteEvents

0
Im dont really have experience on RemoteEvents. You think you can help me out? gamerpenguinpvp34 2 — 3y
0
Create a new "RemoteEvent" object in ReplicatedStorage. Since you are doing Client to server communication, you would put game.ReplicatedStorage.RemoteEvent:FireServer(whatever information you want to fire). On the server side script, do something like game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect() or :Wait(), depending on how you're coding. Everything else is just normal events. kjljixx 42 — 3y
0
Ok. I will try that tomorrow and I will update you gamerpenguinpvp34 2 — 3y
0
After a while I got it working, thanks man gamerpenguinpvp34 2 — 3y
Ad

Answer this question