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

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

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

✓ Accepted answer

You can use RemoteEvents

4 comments

0

Im dont really have experience on RemoteEvents. You think you can help me out?

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.

0

Ok. I will try that tomorrow and I will update you

0

After a while I got it working, thanks man

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