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

Why is my RemoteEvent only working in Studio's Play mode?

Hello again. I'm having trouble with a RemoteEvent. It involves a LocalScript inside an ImageButton and a server-side script inside ServerScriptService. The two scripts work perfectly in Studio's Play mode, but not in-game. Here's the two scripts.

Local script:

local storage = game:GetService("ReplicatedStorage")
local remote = storage.ShrinkRemote

local plr = game.Players.LocalPlayer
local button = script.Parent
local value = plr.PlayerGui.ScreenGui.ScaleValue

button.MouseButton1Click:Connect(function()
	if button.Image == "rbxassetid://2310019779" then
		if value.Value == false then
			print("Shrink button fire!")
			value.Value = true
			remote:FireServer()
		end
	end
end)

And the server script:

local storage = game:GetService("ReplicatedStorage")
local remote = storage.ShrinkRemote

remote.OnServerEvent:connect(function(plr)
	local chr = plr.Character
	local size = plr.PlayerGui.ScreenGui.SizeValue
	
	print("Shrink phase 2 reached!")
	
	for i=0,50 do
		size.Value = size.Value - 0.0137254902
		chr.Humanoid.BodyDepthScale.Value = size.Value
		chr.Humanoid.BodyHeightScale.Value = size.Value
		chr.Humanoid.BodyWidthScale.Value = size.Value
		chr.Humanoid.HeadScale.Value = size.Value
		chr.Humanoid.WalkSpeed = chr.Humanoid.WalkSpeed - 0.196078431
		chr.Humanoid.JumpPower = chr.Humanoid.JumpPower - 0.392156863
		wait(0.005)
	end
	print("Shrinking was a success!")
end)


By looking at the printed text in the Developer Console, I can deduce that the LocalScript did in fact fire the RemoteEvent, but for whatever reason, the server-side script is not receiving it. The last print I get when pressing the button is "Shrink button fire!". Any help would be greatly appreciated. Thank you.

1 comment

0

connect is deprecated, use Connect.

1 answer

✓ Accepted answer

###In Studio's Play Solo mode, there is no separation of the server and client. This is why the server was able to access PlayerGui's descendants. In a real game, the server does not see its descendants. It just acknowledges the fact that it exists but that's about it. You don't need any RemoteEvents at all, even for changing the WalkSpeed as any humanoid changes are replicated to the server.

local client = game:GetService("Players").LocalPlayer
local chr = client.Character or client.CharacterAdded:Wait()
local size = client.PlayerGui.ScreenGui.SizeValue
local value = client.PlayerGui.ScreenGui.ScaleValue

script.Parent.Activated:Connect(function()
    print("Shrink phase 2 reached!")

    if button.Image == "rbxassetid://2310019779" then
        if not value.Value then
            print("Shrink button fire!")
            value.Value = true
            remote:FireServer()
        end
    end

    for i=0,50 do
        size.Value = size.Value - 0.0137254902
        chr.Humanoid.BodyDepthScale.Value = size.Value
        chr.Humanoid.BodyHeightScale.Value = size.Value
        chr.Humanoid.BodyWidthScale.Value = size.Value
        chr.Humanoid.HeadScale.Value = size.Value
        chr.Humanoid.WalkSpeed = chr.Humanoid.WalkSpeed - 0.196078431
        chr.Humanoid.JumpPower = chr.Humanoid.JumpPower - 0.392156863
        wait(0.005)
    end
    print("Shrinking was a success!")
end)

###You'll probably want to fix the placements of the if statements but it was just a simple fix. And remember, if you're working with GUIs, do it on the client!

2 comments

0

Thanks for the answer. I had already fixed the problem by the time you posted this by moving the values in the GUI into the player backpack. I do in fact need RemoteEvents, because if I do this completely locally, the changes won't show up to other players, you just look like a regular-size character half sunken into the floor. Thanks for the answer though!

0

Thanks to you too! The GUI changes should have been done on the client though, lol.

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