✓ Accepted answer
Ok so here are some things I need to say, the first is try using UserInputService for the key pressed events as that is the "modern" way to do it. The next thing is that when you're checking to see whether or not a player is hit by the mouse, make sure to find Humanoid otherwise it would be counting parts and such. And last is try using Debris for things you want to be removed. If you're unsure about all that just look it up on google, I'm sure some neat explanations will pop up, anyways, here's the code:
Put this in a local script:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Players = game:GetService("Players")
local UserInput = game:GetService("UserInputService")
local Debris = game:GetService("Debris")
UserInput.InputBegan:Connect(function(keycode)
if keycode.KeyCode == Enum.KeyCode.F and Player.TeamColor == BrickColor.new("Really red") then
local Hit = Mouse.Target
if Hit then
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
local PlayerHit = Players:GetPlayerFromCharacter(Hit.Parent)
game.ReplicatedStorage.BlindPlayerGet:FireServer(PlayerHit.Name)
end
end
end
end)
game.ReplicatedStorage.BlindPlayerDo.OnClientEvent:Connect(function(PlayerHit)
if PlayerHit ~= Player.Name then
else
local Blind = Instance.new("ColorCorrectionEffect",game.Lighting)
Blind.Brightness = -1
Blind.Name = "BlindF"
Debris:AddItem(Blind,8)
end
end)
Put this in a server script (make sure to put it in ServerScriptService):
game.ReplicatedStorage.BlindPlayerGet.OnServerEvent:Connect(function(player, PlayerHit)
game.ReplicatedStorage.BlindPlayerDo:FireAllClients(PlayerHit)
end)
Oh and one more thing, make sure to create two remote events (inserted in ReplicatedStorage) called BlindPlayerGet and BlindPlayerDo
Hope this helps! :)
1 comment
Mouse.Target ignores players, so you will need to change the mouses target filter. This might help you https://devforum.roblox.com/t/issue-with-the-mouses-target/285197