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

Debug prints but other player's gui doesn't open?

I'm trying to make it to where when a player clicks on another player a gui opens on their screen. I have this as a local script:

local Player = game.Players.LocalPlayer -- Getting the player   
local Mouse = Player:GetMouse() -- Getting the players mouse


Mouse.Button1Down:Connect(function() -- Detecting when player presses the left mouse button
	
    if Mouse.Target.Parent:FindFirstChild("Humanoid") and 
        game.Players.LocalPlayer.TeamColor.Name == ("Dirt brown") then -- Checking if the Mouse is over a player
        print(Mouse.Target.Parent.Name) 
	local mousetarget = Mouse.Target.Parent
		game.ReplicatedStorage.SellPistol:FireServer(mousetarget)
		
	


    end
end)

Someone told me to use get player on the script this connects to under ServerScriptService:

local SellPistol = game.ReplicatedStorage.SellPistol

local function onSellPistol(player, mousetarget)
    local target = game:GetService("Players")[mousetarget.Name]
    target.PlayerGui.StartScreen.Frame.Visible = true
    print("Debug")
end

SellPistol.OnServerEvent:Connect(onSellPistol)

now the debug prints but the gui doesn't open why?

1 answer

✓ Accepted answer

Why don't you just use mousetarget on line 5 instead of creating a new target variable on line 4? Also your target variable is the name of the player, so it won't work because PlayerGui is not the child of the player name; it is the child of the player. Here is what I'm talking about:

local SellPistol = game.ReplicatedStorage.SellPistol

local function onSellPistol(player, mousetarget)
	mousetarget.PlayerGui.StartScreen.Frame.Visible = true
	print("Debug")
end

SellPistol.OnServerEvent:Connect(onSellPistol)

2 comments

0

Sorry if the indentation or I guess the whole code looks weird. I had to do this on mobile, so I have no idea what the code block looks like to you. But I hope this helps!

0

no problem it still helps

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