Make part move on TextButton click

Hello. I’m trying to make a UI button move a part inside of workspace on click. My attempt was to fire a remoteEvent using the localScript inside of the textbutton. My issue is that the remoteEvent starts of as soon as you join, and not whenever you click the button.

Here’s the localScript inside the textButton:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.SemEvents:WaitForChild("LoseHat")
local nextText = script.Parent.Parent.WhatTheySaid1

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
	script.Parent.Visible = false
	nextText.Visible = true
	remoteEvent:FireServer()
end)

and here’s the script inside ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage.SemEvents:WaitForChild("LoseHat")

local function doStuff()
game.Workspace.SemEggObjective.nohat.Position = Vector3.new(156.98, 4.493, -121.597)
game.Workspace.SemEggObjective.withhat.Position = Vector3.new(156.98, -10.775, -147.602)
game.Workspace.SemTeleports:Destroy()
end

remoteEvent.OnServerEvent:Connect(doStuff())
1 Like

inside the serverscript, you should assign a function to the .OnServerEvent connection, not a function call.
It should look like this

remoteEvent.OnServerEvent:Connect(doStuff)

Other than that both your scripts look fine

2 Likes

It works perfectlt now. Thank you!

2 Likes