Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

0

line 11 should be the problem

1 answer

✓ Accepted answer

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)

2 comments

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.

0

Why use Destroy, Not remove

This discussion is preserved as it was. New answers, comments, and votes are closed.