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

GUI Button works during test game (Studio) but not on a server?

I have an image button that makes the player smaller when clicked.

It works fine in Studio when I test it, but when I upload it to Roblox and play it, it doesn't work.

function onClick()
	local h = game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
	if h~=nil then
h:findFirstChild("BodyHeightScale").Value= .7
h:findFirstChild("BodyWidthScale").Value= .7
h:findFirstChild("HeadScale").Value= .7
h:findFirstChild("BodyDepthScale").Value= .7 end
end

script.Parent.MouseButton1Click:connect(onClick)

Any ideas on how to make it work when the game is online? Please be descriptive, it really helps a lot! Thanks

EDIT: I'd like to add that this script above is located here:

Workspace>GUIscript>ScreenGUI>ImageButton>Script <------

1 answer

✓ Accepted answer

Firstly, I'm guessing that this is a server script. The server script can't run inside the player's PlayerGui, but only the workspace and the ServerScriptService.

Also, connect and findFirstChild are deprecated. Change it to Connect and FindFirstChild. That wasn't the reason the script wasn't working, but it is good to keep that in mind.

Another thing is that even if you did change this to a Local Script, it still wouldn't work with FIltering Enabled on. It will not work as expected in online mode. Other players won't see your character as smaller, but you will. The best way to do this is using Remote Events:

First, put a RemoteEvent named Resize in the ReplicatedStorage

Put this in a Script in the ServerScriptService.

local resize = game:GetService("ReplicatedStorage"):WaitForChild("Resize")
resize.OnServerEvent:Connect(function(player,num)
	if player.Character == nil then return end
	local h = player.Character:FindFirstChild("Humanoid")
	if h~=nil then
		h:WaitForChild("BodyHeightScale").Value= num
		h:WaitForChild("BodyWidthScale").Value= num
		h:WaitForChild("HeadScale").Value= num
		h:WaitForChild("BodyDepthScale").Value= num
	end
end

And put this in a LocalScript inside the ImageButton.

function onClick()
	local resize = game:GetService("ReplicatedStorage"):WaitForChild("Resize")
	resize:FireServer(0.7)
end

script.Parent.MouseButton1Click:Connect(onClick)

2 comments

0

Wow, thank you for all the info! I understand what's going on now. This really really helped and thanks for the explanation!

0

You're welcome!

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