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

How do I manipulate a gui to only show up for a certain player?

Game has filtering enabled turned on, and the local script is located in: game.StarterGui.ScreenGui.Frame.ImageButton.Shopscript

local GUI = script.Parent.Parent.Parent
local imagebutton = script.Parent
local Replistore = game:GetService("ReplicatedStorage")
local Frame = script.Parent.Parent
local MoveGui = Frame:WaitForChild("CloseGui") 
local Shopbulletin = Frame.TextLabel
local SHOPbutton = game.Workspace.SHOPbutton
local Buttondebounce = true
local openagain = true

function checkplayer(otherpart)
	local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
	if humanoid ~= nil then
		plr = game.Players:GetPlayerFromCharacter(otherpart.Parent)
		points = plr.leaderstats.Points
	end
end

function checkpurchase()
	local checksword = plr.Backpack:FindFirstChild("ClassicSword")
	if points.Value >= 40 and checksword == nil then
		points.Value = points.Value - 40
		Replistore.ClassicSword:Clone().Parent = plr.Backpack
		Replistore.ClassicSword:Clone().Parent = plr.StarterGear
	elseif checksword ~= nil then
		Shopbulletin.Text = "You already have a sword!"
		wait(1.5)
		Shopbulletin.Text = "Welcome to the place shop!"
	else
		local Text = script.Parent.Parent.TextLabel
		local temppoints = 40 - points.Value
		Shopbulletin.Text = "You need to have "..temppoints.." more points!"
		wait(1.5)
		Shopbulletin.Text = "Welcome to the place shop!"
	end
end

function closegui()
	Frame:TweenPosition(UDim2.new(-1.5, 0, 0, 0)) 
	wait(1.5)
	script.Parent.Parent.Visible = false
	openagain = true
end

function opengui()
	script.Parent.Parent.Visible = true
	Frame:TweenPosition(UDim2.new(0.25, 0, 0, 0))
	openagain = false
	wait(1.5)
end

function Openshop(otherpart)
	if not Buttondebounce and not openagain then
		return
	end
	Buttondebounce = false
	checkplayer(otherpart)
	SHOPbutton.BrickColor = BrickColor.Red()
	opengui()
	wait(1)
	SHOPbutton.BrickColor = BrickColor.Gray()
	Buttondebounce = true
end

imagebutton.MouseButton1Click:connect(checkpurchase)
MoveGui.MouseButton1Click:connect(closegui)
SHOPbutton.Touched:connect(Openshop)

I've tested this in a test local server w/ two players, and when one player touched the button, the Gui showed up for both players, even for the other player who didn't touch the button. I intended for the gui to just show up for the player who pressed the button, and I'm not sure what to do from here. Thanks in advance!

1 comment

0

Can you add in some prints to find what is being ran when and where.

1 answer

✓ Accepted answer

Right now your checkplayer function isn't doing anything. When someone touches the part, it fires the event in every player's Shopscript and calls the opengui function. You can fix this by checking to see if the player who touched the part is indeed the local player of the script:

local player = game.Players.LocalPlayer

function Checkplayer(otherpart)
	local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		return game.Players:GetPlayerFromCharacter(otherpart.Parent)
	end
end

function Openshop(otherpart)
	if Buttondebounce and openagain then
		Buttondebounce = false
		if player == Checkplayer(otherpart) then
			SHOPbutton.BrickColor = BrickColor.Red()
			opengui()
			wait(1)
			SHOPbutton.BrickColor = BrickColor.Gray()
			Buttondebounce = true
		end
	end
end

#####Note this is not the full script, just the portions of your original code that I modified.


As an aside, it might be beneficial to consider using a RemoteEvent for this problem. Rather then connecting a bunch a touched events, you could connect it to a single server sided touched event and then fire an event to the client whose shop GUI should open.

However, this is not necessary as your code should work given my fixes.

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