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

How to find the Player of someone when they touch a certain part?(Fixed code block)

Asked by 10 years ago

I am putting a Message in a players PlayerGui so only they see it when they touch the part... I think in some way, I need to use GetPlayerFromCharacter but i'm not sure how to use this with using Instance.new so here is my script (Not Local)

SP = script.Parent
SPP = script.Parent.Parent
Debounce = false

SP.Touched:connect(function(hit)
    local Human_Check = hit.Parent:FindFirstChild("Humanoid")
    if SPP.Enable.Value == false then
        SP.Transparency = 0.5
        wait(0.1)
        SP.Transparency = 0
        local msg = Instance.new("Message"), game.Players.GetPlayerFromCharacter.PlayerGui
        msg.Text = "Please wait a few seconds and try again"
        wait(3)
        msg:remove()
    end
end)

I would like a little lesson on arguments - in the Object Browser and example is GetPlayerFromCharacter(character), the (character) confuses me a bit- if possible. This script is not finishes, so please do not add in my Debounce. Enable is a BooleanValue which is getting activated by another part.

0
line 11 should be the problem alphawolvess 1784 — 10y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

You're on the right track, you do need the GetPlayerFromCharacter method. But the method takes a character as it's arguments and is a method of game.Players..

local SP = script.Parent
local SPP = script.Parent.Parent
local db = false

SP.Touched:connect(function(hit)
    if db == false then db = true
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr then
            if SPP.Enable.Value == false then
                SP.Transparency = 0.5
                wait(0.1)
                SP.Transparency = 0
                local m = Instance.new('Message',plr.PlayerGui)
                m.Text = "Please wait a few seconds and try again"
                wait(3)
                m:Destroy()
            end
        end
        db = false
    end
end)
0
I didn't really like how you added and changed the name of my Debounce and edited my script for parts I didn't need changed... I'm using it but changing it back to my way minus the fixes you did to see if it works. alphawolvess 1784 — 10y
0
Why use Destroy, Not remove alphawolvess 1784 — 10y
Ad

Answer this question