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

? Need help placing a mousebutton1click code in a remotefunction code

I made a code that puts my username in a string value that I have placed in my startergui and then I made a remote function to basically make a copy of that string value and put it in the workspace and now I want to add a text button so that the remote function will not run until I click on the text button… I've tried a couple times and it will not work with the mousebutton1click method and I do not understand why because when I take out the mousebutton1click code it works perfectly fine... Does anyone know how I could do this?

Localscript :

local player = game.Players.LocalPlayer
local val = game.StarterGui.Value


		val.Value = player.Name.."1"

		game.ReplicatedStorage.RemoteFunction:InvokeServer(val.Value)

Script :

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player,code)	
local vall = Instance.new("StringValue")
vall.Parent = workspace
vall.Value = code
end

1 answer

✓ Accepted answer

I assume that your codes are based on StarterGui , which is the wrong way to get the player's gui. Your GUI path should be this:

--Local Script
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local Button = PlayerGui. -- Your path
Button.MouseButton1Click:Connect(function()
	--Your codes
end)

I hope this solution helps you. However, due to the limited details, it may not work fine for you.

More Details: PlayerGui.

2 comments

0

It worked, thank you so much.

0

You may want to accept my answer. ;))

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