Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
Wow, thank you for all the info! I understand what's going on now. This really really helped and thanks for the explanation! ShinyGriffin 129 — 6y
0
You're welcome! UgOsMiLy 1074 — 6y
Ad

Answer this question