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

Why this script is not working?

Asked by 10 years ago

Hi guys, it's since 2 weeks that I'm trying to resolve this problem, what I want to do is to "check" the corpse of a player while who's checking is the detective, this works but what I REALLY want to do is: If the player has the mouse over my ClickDetector AND is in a distance of 6 studs between the player and the corpse AND the player pressed "E" then do.... But it works like this "if statement" is ignored...

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local pInfo = script.Parent.PlayerInfo.Wrapper
local target = script.Parent.Parent -- The corpse

function func_1637702a() -- Obfuscation ftw
    -- hide the corpse (transparency => 0) and spawn barrel
end

function keyPress(par1)
    if par1 == "e" then
        local td = player:FindFirstChild("TempData")
        local tp = td:FindFirstChild("Type")
        if player:DistanceFromCharacter(target.Torso.Position) <=  6 then
            if tp.Value == "Traitor" then
                if pInfo.HealthStatus.Text == "Corpse" then
                    func_1637702a()
                else
                    print("The traitor tried to hide an alive player")
                end
            else
                print("A player tried to hide a corpse while not being a traitor")
            end
        end
    end
end

mouse.KeyDown:connect(keyPress)

I want to use the method "MouseHoverEnter" but this will work only the function on mouse hover the clickdetector, and this function it's called when the player presses "e", so I need to check if the mouse is STILL on the clickdetector and I don't know how to do that, thanks for helping!

1 answer

Log in to vote
1
Answered by
OniiCh_n 410 Moderation Voter
10 years ago

ClickDetector only detects clicks. You would need to use mouse.Target instead. MouseHoverEnter only works GUIs (I believe). The mouse.Target can only be used on parts, so keep that in mind. That answers one of your problems...

Ad

Answer this question