Help with remote event

i have this script thats on a server script

game.ReplicatedStorage.SizeUp.OnServerEvent:Connect(function(plr)

	local UserInputService = game:GetService("UserInputService")
	local LocalPlayer = plr
	local button = game.StarterGui.SizeUp.SizeUpB

	-- Function to check if a tool is being equipped
	local function isToolEquipped()
		local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
		for _, child in pairs(character:GetDescendants()) do
			if child.ClassName == "Tool" then
				return true
			end
		end
		return false
	end

	-- Function to run when button is clicked
	local function onButtonClicked()
		if not isToolEquipped() then
			-- Run the rest of the script
			local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
			local currentScale = character:GetScale()

			if currentScale == 1.0 then
				character:ScaleTo(1.5)
			elseif currentScale == 0.5 then
				character:ScaleTo(1.0)
			end
		else
			-- Do nothing if a tool is being equipped
		end
	end

	button.MouseButton1Click:Connect(onButtonClicked)
end)

and basically what its supposed to do is after the player clicks a button on their screen it sends a message to the remote event then this script fires and when i put print statements they print but the character wont size up like its supposed to.
any ideas on what might be wrong?

1 Like

So the problem I am seeing right now is that you have it so when you press a button you size up, the problem with this is that the button is in StarterGui, a common misconception, the UI the players see is not in StarterGui, its in PlayerGui.

Along with that what I would recommend is instead of detecting when the button is pressed on the server, check when it happens on the client, then send the remote event to the server telling it to size up the player, this might be better for performance, maybe, maybe not idk. But its good practice nonetheless I think.


But yes the problem right now is that the button you are trying to see is clicked, is never clicked, cause the actual button is in the players PlayerGui.

Which can be accessed with via Player.PlayerGui

2 Likes

Basically everything that @FroDev1002 said,

No need to reassign the player?

2 Likes

i have this on a local script

script.Parent.Activated:Connect(function()
	
	game.ReplicatedStorage.SizeUp:FireServer()
	
end)

is that what you meant?
also it worked but it was only able to size up once

your right ill replace the local players with just plr

Uhh, no…
replace:

local button = game.StarterGui.SizeUp.SizeUpB

with this:

local button = plr.PlayerGui.SizeUp.SizeUpB

It might also be that your only sizing up and not back down.

This is also not necessary:

1 Like

yes i did that but i also just removed

local localplayer = plr
``

Well from your code you can only size up once.

after what I believe is the first time, its sets your size to 1.5, and after that all of the if statements return false so it never changes

2 Likes

i have another script that sizes it down but its just a local script ill go turn it into a server script with a remote function and that should be the fix i just made the mistake of making almost everything local

that seemed to be the fix but now it when it reaches either 1.5 or 0.5 it never goes to 1.0
both scripts are the same expect the remote event name and this part

			if currentScale == 1.0 then
				character:ScaleTo(0.5)
			elseif currentScale == 1.5 then
				character:ScaleTo(1.0)
			end

im sorry about the endless amount of issues im not very good at scripting

1 Like

instead of the if statements, not sure this would solve the issue, but its much cleaner, you can do this:

-- This is for removing scale
local NewScale = math.clamp(currentScale - 0.5, 0.5, 1.5)
character:ScaleTo(NewScale)

-- This is for adding scale
local NewScale = math.clamp(currentScale + 0.5, 0.5, 1.5)
character:ScaleTo(NewScale)
1 Like

this is the issue it still just keeps going from 0.5 to 1.5 after working once im not sure why its not working now because when i had them in just the local script it was working

can I see the code for the client? Like all of it related to this?

1 Like

sizedownserver:


	local UserInputService = game:GetService("UserInputService")
	local button = plr.PlayerGui.SizeDown.SizeDownB

	-- Function to check if a tool is being equipped
	local function isToolEquipped()
		local character = plr.Character or plr.CharacterAdded:Wait()
		for _, child in pairs(character:GetDescendants()) do
			if child.ClassName == "Tool" then
				return true
			end
		end
		return false
	end

	-- Function to run when button is clicked
	local function onButtonClicked()
		if not isToolEquipped() then
			-- Run the rest of the script
			local character = plr.Character or plr.CharacterAdded:Wait()
			local currentScale = character:GetScale()
			-- This is for removing scale
			if currentScale == 1.0 then
				character:ScaleTo(0.5)
			elseif currentScale == 1.5 then
				character:ScaleTo(1.0)
			end
		else
			-- Do nothing if a tool is being equipped
		end
	end

	button.MouseButton1Click:Connect(onButtonClicked)
end)

sizedown local:

script.Parent.Activated:Connect(function()

	game.ReplicatedStorage.SizeDown:FireServer()

end)

sizeup server:

game.ReplicatedStorage.SizeUp.OnServerEvent:Connect(function(plr)

	local UserInputService = game:GetService("UserInputService")
	local button = plr.PlayerGui.SizeUp.SizeUpB

	-- Function to check if a tool is being equipped
	local function isToolEquipped()
		local character = plr.Character or plr.CharacterAdded:Wait()
		for _, child in pairs(character:GetDescendants()) do
			if child.ClassName == "Tool" then
				return true
			end
		end
		return false
	end

	-- Function to run when button is clicked
	local function onButtonClicked()
		if not isToolEquipped() then
			-- Run the rest of the script
			local character = plr.Character or plr.CharacterAdded:Wait()
			local currentScale = character:GetScale()
				if currentScale == 1.0 then
				character:ScaleTo(1.5)
			elseif currentScale == 0.5 then
				character:ScaleTo(1.0)
			end
			
		else
			-- Do nothing if a tool is being equipped
		end
	end

	button.MouseButton1Click:Connect(onButtonClicked)
end)

sizeup local:

script.Parent.Activated:Connect(function()
	
	game.ReplicatedStorage.SizeUp:FireServer()
	
end)

i have versions of these for keyboard inputs too that arent connected to any remote events and also a local script that changes speed based on size let me know if you want to see those too

Ok please rewrite your server code to do what I mentioned up here:

As again detecting the button press on the server isnt needed, and it would be best to just do it on the client, and then tell the server to size up or down

1 Like

how would i be able to do that what part do i need to remove and then add?

Heres an example, I just removed some values:

game.ReplicatedStorage.SizeUp.OnServerEvent:Connect(function(plr)

	local UserInputService = game:GetService("UserInputService")

	-- Function to check if a tool is being equipped
	local function isToolEquipped()
		local character = plr.Character or plr.CharacterAdded:Wait()
		for _, child in pairs(character:GetDescendants()) do
			if child.ClassName == "Tool" then
				return true
			end
		end
		return false
	end

	-- Function to run when button is clicked
	if not isToolEquipped() then
		-- Run the rest of the script
		local character = plr.Character or plr.CharacterAdded:Wait()
		local currentScale = character:GetScale()
			if currentScale == 1.0 then
			character:ScaleTo(1.5)
		elseif currentScale == 0.5 then
			character:ScaleTo(1.0)
		end
	else
		-- Do nothing if a tool is being equipped
	end
end)

Not exactly sure this would work as I didnt test it, but it should do it, now anytime the remoteEvent is fired they will be sized up, you can do this same thing with the size down script as well!

1 Like

so if i put this in the server script it should work? do i need to change the local script?

No I dont think you need to change the local script, it should work

1 Like