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

Why is my blinding spell not detecting a player?

Asked by 3 years ago

Basically the code is supposed to, when you press F, blind the player your mouse is on for 8 seconds. Both are local scripts by the way.

Player detector.

local player = game.Players.LocalPlayer
    local mouse = player:GetMouse()

    mouse.KeyDown:connect(function(key)
        if key == "f" and player.TeamColor == BrickColor.new("Mulberry") then
        local hit = mouse.Target
        if hit.Parent then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent);
               if player then
                local og = script.LocalScript
                local clne = og:Clone()
                clne.Parent = player.PlayerScripts
        end
    end
end    
    end)

Actual blinding code below.

wait(.3)
game.Lighting.Blur.Enabled = true
wait(8)
game.Lighting.Blur.Enabled = true
script:Destroy()
0
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 DarkDanny04 407 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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 --you can change it to whatever team color you want
        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! :)

0
Thank you SO much! youngsavagehard 20 — 3y
Ad

Answer this question