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

Filtering Enabled Flashlight Key Function thing?

Could anyone help me with turning this script FE compatible, I need it for a horror game of mine.

local mouse = game.Players.LocalPlayer:GetMouse()
function Light()
	local player = game.Players.LocalPlayer
	local playerChar = player.Character
	local playerLight = playerChar.Torso:FindFirstChild("Light")
	local playerSound = playerChar.Torso:FindFirstChild("Sound")
	if playerLight then
		playerSound:Destroy()
		playerLight:Destroy()
	else
		light = Instance.new("SpotLight",playerChar:FindFirstChild("Torso"))
		light.Name = "Light"
		light.Range = 16 
		light.Brightness = 10 
		light.Shadows = true
		local play = Instance.new("Sound",playerChar:FindFirstChild("Torso"))
		play.SoundId = "http://www.roblox.com/asset/?id=198914875" 
		play:Play()
		
	end
end

mouse.KeyDown:connect(function(key)
	key = key:lower()
	if key == "f" then -
		Light()
	end
end)

Thank you.

1 answer

✓ Accepted answer

Hi AgentGalahad,

The reason you're having a problem with this script in FE is because you're running physical changes through local scripts. If you want things to have server changes, then you need to run them through ServerScripts. Local Scripts will run locally and will not let the whole Server see the changes made through local scripts in FE.

##Here, I'll just give you an example of how you can handle physical changes that you want the whole server to do.

LOCAL SCRIPT

----------------- Services ----------------------
local players = game:GetService("Players");
local rs = game:GetService("ReplicatedStorage");
local uis = game:GetService("UserInputService");
----------------- Services ----------------------

----------------- Initial Variables ----------------------
local player = players.LocalPlayer;
local re = rs:WaitForChild("Make Part");
----------------- Initial Variables ----------------------

function do_it(key, gp) -- Function for UserInputService
	if key.KeyCode == Enum.KeyCode.Q and not gp then -- Checks if the player pressed Q and if the player was not typing while he/she did so.
		re:FireServer(); -- Fires the RemoteEvent, which fires the function connected to the RemoteEvent, which is in a ServerScript I will post below.
	end -- end for if statement
end -- end for function.

uis.InputBegan:Connect(do_it); -- Connecting the function to the event.

SERVER SCRIPT

----------------- Variables ----------------------
local rs = game:GetService("ReplicatedStorage");
local re = rs:WaitForChild("Make Part");
----------------- Variables ----------------------

re.OnServerEvent:Connect(function(plr) -- The function that connects the RemoteEvent .OnServerEvent to this function below. The parameter is the player that activated the event.

	--------------------- PHYSICAL CHANGES ---------------------

	local part = Instance.new("Part"); 
	local char = plr.Character or plr.CharacterAdded:Wait();
	local torso = char:WaitForChild("HumanoidRootPart");
	
	part.CFrame = torso.CFrame * CFrame.new(0, 7, 0);
	part.Size = Vector3.new(math.random(5), math.random(5), math.random(5));
	part.CanCollide = false;
	part.BrickColor = BrickColor:random();
	part.Shape = Enum.PartType.Ball;
	part.Material = Enum.Material.Neon;	
	
	local weld = Instance.new("Weld");
	local temp = torso.CFrame;
	weld.Parent = part;
	weld.Part0 = torso;
	weld.Part1 = part;
	weld.C0 = torso.CFrame:inverse() * temp;
	weld.C1 = part.CFrame:inverse() * temp;
	
	part.Parent = workspace;
	
	--------------------- PHYSICAL CHANGES ---------------------
end)  -- end for anonymous function.

###Well, I hope I helped and I know this doesn't address your problem directly but, it's an example you can use to solve your problem. I didn't want to just give you the answer, I want you to work for it yourself. So, the RemoteEvent is located under ReplicatedStorage, the ServerScript is and I think needs to be under ServerScriptService, and the local script needs to be on the client, I put it under StarterGui, which goes to the client.

##Have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

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