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

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

Asked by
TofuBytes 500 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by 10 years ago

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!

0
It doesn't seem to work. I'm not getting an output error either TofuBytes 500 — 10y
0
Oh sorry... I found my error! Let me edit that! TheStudentPilot 75 — 10y
0
Edited, please let me know if it still doesn't work! TheStudentPilot 75 — 10y
Ad

Answer this question