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

How can I fire a RemoteEvent when I press 'e'?

I'm trying to make a RemoteEvent fire when a player presses 'e' when in a certain distance of the brick. I'm uncertain on how I :GetMouse() and this is a LocalScript for FilteringEnabled. Does anyone know how to fix this?

for _,v in pairs(game.Players:GetPlayers()) do
mouse = v:GetMouse()
end

debounce = false 
Object = script.Parent
 
mouse.KeyDown:connect(function(key)
    for i,v in pairs(game.Players:GetPlayers()) do
            distance = 5
            if (v.Torso.Position - Object.Position).magnitude <= distance then
                if (key:lower()) == "e" and not debounce then  
				debounce = true
				game.ReplicatedStorage.Found_Phone:FireServer()
				script.Parent:Destroy()
                end
            end
        end
end)

1 answer

Try doing local player = game.Players.LocalPlayer and under that local mouse = player:GetMouse() and do local workplayer = player.Name and then do local actualplayer = Workspace:FindFirstChild(workplayer)

Then do

mouse.KeyDown:connect(function(key)
	disatance = 5
	if (actualplayer.Torso.Position - Object.Position).magnitude <= distance then
		if key:byte() == 101 then
			-- your code here
		end
	end
end)

You can find the KeyCodes here.

If that doesn't work, please let me know.

If it still doesn't work, please let me know!

3 comments

0

It doesn't seem to work. I'm not getting an output error either

0

Oh sorry... I found my error! Let me edit that!

0

Edited, please let me know if it still doesn't work!

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