Need help working my GUI TextButton!

I’m pretty new at scripting and I’m trying to make a GUI button that refreshes the player’s appearance but it seems to not be working. I checked the output and this is what it says…

Images:
Capture explorer

Script:


script.accept.MouseButton1Click:connect(function(plr)
local Pos = plr.Character:GetPrimaryPartCFrame()
	plr:LoadCharacter()
	if plr.Character then
	plr.Character:SetPrimaryPartCFrame(Pos)
	end
end)```

Where is the script and try capitalizing accept in the first line

script.Parent.MouseButton1Click:Connect(function(plr)
    local Pos = plr.Character:GetPrimaryPartCFrame()
	plr:LoadCharacter()
	if plr.Character then
	    plr.Character:SetPrimaryPartCFrame(Pos)
	end
end)

Using script.Accept assumes that the button is inside the script. Since the script is parented to the button, you want to use script.Parent

You forgot to capitalize the A in Accept.

script.accept.MouseButton1Click:connect(function(plr)

But, you need to use script.Parent instead of script.Accept due to the button being the parent of the script, not a child.

I tried this but for some reason, It’s not refreshing the character.

New Output:
Refresh

I just realized it didn’t work, I’ll update it soon

1 Like

Refreshing characters only works on a server script
edit: I think

MouseButton1Click does not give the player, you will need to use Players.LocalPlayer.

Also, Player:LoadCharacter() will not work on the client.

you should try using Character:MoveTo(Vector3.new()) instead of setprimarypartcframe

Don’t manipulate the character in a local script

local plr=game:GetService('Players').LocalPlayer
script.Parent.MouseButton1Click:connect(function()
local Pos = plr.Character:GetPrimaryPartCFrame()
	plr:LoadCharacter()
	if plr.Character then
	plr.Character:MoveTo(Pos)
	end
end)

@jrdonat was right, you can’t use LoadCharacter on the client

I tried again, hopefully this is an improvement

-- Server script
local plr = script.Parent.Parent.Parent.Parent.Parent
	
script.Parent.MouseButton1Click:Connect(function()
	local Pos = plr.Character:GetPrimaryPartCFrame()
	plr:LoadCharacter()
	if plr.Character then
		plr.Character:MoveTo(Pos)
        print('refreshed')
	end
end)
2 Likes

Thank you so much! It worked :smiley:

1 Like