Problem with a part spawned locally

So, i have a problem with one of my surface gui and image label. Let me explain the situation. The player has an item which, when tool.Activated, spawn a part in front of him. The particular thing is, it spawns locally, with a local script. Linked to this part, and also locally, a surface gui with a button. The button doesn’t work when the player try to press it. I already looked at google and saw some solutions like: there should be no part (even slightly) in front of the Surface obviously, also the Surface should be on PlayerGui with the adornee set to the part. But even with these things set, the button doesn’t want to print the word « Worked ». As the 3 lines of codes are simple, i also didn’t make a mistake about the code.

Anyone got an idea? I could think of the possibility that the part should « exist » in the view of the server and the surface should be displayed on a part created by the server but i am not sure about this.

Thanks to the one who will find the solution!

you can make it so
tool.Activated
then fire a remote event to a server then
in the server script make a part in front of the player and put a surface gui this should probably work

Yes it should work but as it will display the player’s stats, i don’t want everyone to see the book opened. This is also the reason why the part spawns locally and not via a remote event.

Can you show the code? Are you sure you’re connecting a mouse click event to the button?

Yes. The code is:
local btn = script.Parent
btn.MouseButton1Click:Connect(function()
print(« Worked »)
end)

As i am not in front of my pc but in mobile, i maybe did a mistake but i think this is how i wrote it. Also i am not a beginner, i would know if i did a mistake with this simple script.

It would also be helpful to see the setup of the tool, the surface gui, and the button in the explorer after you spawned the part with the tool. The code that handles tool.Activated would also be useful to see

Alright, i am also almost at home. Once i am back, i’ll screenshot everything :+1: thanks for helping me anyway

1 Like

Here we go. This is the tool local script:

wait(0.5)
repeat wait() until game.Players.LocalPlayer.Character.Humanoid
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local handle = script.Parent
local tool = handle.Parent
local Replic = game.ReplicatedStorage
local InUse = false

tool.Activated:Connect(function()
	Replic.Value:FireServer("RefreshStats", handle)

	if not char:FindFirstChild("page") and not char:FindFirstChild("screen") then
		InUse = true


		local armWeld = Instance.new("Weld")
		armWeld.Part0 = char.Torso
		armWeld.Part1 = char["Right Arm"]
		armWeld.Parent = char

		local page = Replic:WaitForChild("Book"):FindFirstChild("page"):Clone()
		local screen = Replic:WaitForChild("Book"):FindFirstChild("screen"):Clone()
		
		local menu = plr.PlayerGui:WaitForChild("Template_menu"):Clone()
		menu.Name = "menu"
		menu.Parent = plr.PlayerGui
		menu.Adornee = screen
		
		local w1 = Instance.new("WeldConstraint", page)
		w1.Part0 = page
		w1.Part1 = screen

		page.Parent = char
		screen.Parent = char

		screen.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0, 0, -6)
		screen.CFrame = page.CFrame

		local w2 = Instance.new("WeldConstraint", page)
		w2.Part0 = page
		w2.Part1 = char.HumanoidRootPart

	else
		InUse = false
		char:FindFirstChild("Weld"):Destroy()
		char:FindFirstChild("page"):Destroy()
		char:FindFirstChild("screen"):Destroy()

	end
end)

local armOffset = char.Torso.CFrame:Inverse() * char["Right Arm"].CFrame

game:GetService("RunService").Heartbeat:Connect(function()
	if InUse then
		local armWeld = char:FindFirstChild("Weld")

		local cframe = CFrame.new(char.Torso.Position, mouse.Hit.Position) * CFrame.new(0, 0.5, -0.5) * CFrame.Angles(math.pi/2, 0, 0)
		armWeld.C0 = armOffset * char.Torso.CFrame:toObjectSpace(cframe)
	end
end)

the Surface setup: https://gyazo.com/54647637a505355e9c274b5374813381
the tool setup: https://gyazo.com/eb6b6185298413d539e952dd2d16e44e

The part spawn properly in front of the player as the adornee is set properly too because i can see the Surface on the part. And i tried it many times, it does work every time i activate it. But the case button still is an issue @heII_ish

Alright so, i found the issue. When you have a SurfaceGui adornee’d (idk if this word exist) to a part inside character’s model, you can’t click the button. The mistake was then the parent of the part which have the SurfaceGui.