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

MouseButton1Click to remote function doesn't work?

So I've been testing couple of scripts they did worked but that one didn't

Here is the main script :

player = game.Players.LocalPlayer




script.MyFunction.OnServerInvoke = function(player)
	local part = Instance.new("Part")
	part.Parent = workspace
	part.Name = "Imprintedone"
	part.Anchored = false
	part.Color = Color3.new(Random)
	part.Position = Vector3.new(-35.94, 52.4, -17.69)
end

Note: The main script has Function object in it

InvokeServer server script :

player = game.Players.LocalPlayer
game.StarterGui:WaitForChild("ScreenGui")


game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(function(player)
	game.Workspace.Main.MyFunction:InvokeServer()
end)

game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(player)

It doens't work can anyone tell me why?

note: the InvokeServer server script is in starterpack and a local script as well

1 answer

✓ Accepted answer

First off:

Whatever the player sees on their screen are descendants of their PlayerGui. StarterGui holds guis and stuff that will be parented to the client's playergui when they respawn.

Second off all:

Why are you using RemoteFunctions when you're not returning anything, you should use RemoteEvents.

Try this for the local script:

local player = game.Players.LocalPlayer
local pgui = player:WaitForChild('PlayerGui')
local ui = pgui:WaitForChild("ScreenGui")


ui.TextButton.MouseButton1Click:Connect(function(player)
    game.Workspace.Main.MyFunction:InvokeServer()
end)

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