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

Part that is supposed to be clicked doesn't dispense the GUI?[Answered]

Hi everyone,

I'm trying to dispense a GUI when a certain part is clicked, but it simply doesn't work.

Please check for my mistakes as I'm certainly not the best at scripting. (I dont even understand my mistake)

local btn = script.Parent

local clickde = script.Parent.Parent.Parent.ClickDetector

clickde.MouseClick:Connect(function(playerWhoClicked)

local h = game.Players:GetPlayerFromCharacter(playerWhoClicked)

if h then

local newgui = script.ScreenGui:Clone()

newgui.Parent = h.PlayerGui
		
		
		
end

	
end)


Thanks!

8 comments

0

Is the clickde under the part?

0

Clickde is a child of the part.

0

The PlayerGui is client-side, and is invisible to server scripts, so if I'm correct, it should work in a local script.

0

I used a normal script to dispense GUIs to Players before, through that one is far more complex.

0

You cannot access PlayerGui through ServerScript when FE is turned on. Use Remote events or LocalScripts

0

FE is off.

0

Axceed and Sam you're both wrong, you cannot access it, that's true, but you can clone to it or set a parent to it

0

^ My Bad

1 answer

✓ Accepted answer

The problem with your script is that you assume that click is the same as hit.

You try to get a player from a character but 'playerwhoclicked' isn't a character, it's the player.

A simple fix would be

local btn = script.Parent

local clickde = script.Parent.Parent.Parent.ClickDetector

clickde.MouseClick:Connect(function(click)
	local newgui = script.ScreenGui:Clone()
	newgui.Parent = click:WaitForChild('PlayerGui')
end)

If this still doesn't work, set a comment, but it would be most likely a problem in variables then and not a problem in player detection.

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