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

Why is my image button working perfectly fine in Studio, but doesnt work in servers?

Hi, I made a image button, in starter gui. When I was in studio the image button worked perfectly fine, but when I went to a test server, the image button wasnt doing anything when I clicked it.

why?

Here is my script in the image button

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()


local lore = player.PlayerGui.ChooseCharacter.Background.Zeus.Lore.TextLabel
local gui = player.PlayerGui.ChooseCharacter
local God = player.PlayerGui.ChooseCharacter.God
local button = player.PlayerGui.ChooseCharacter.Background.Zeus

button.MouseButton1Click:Connect(function()
	gui.Background.Visible = false
	game.StarterPlayer.EnableMouseLockOption = true
	lore.Visible = false
	God.Value = "Zeus"
	
	character.UpperTorso.CFrame = CFrame.new(182, 0.5, 39)  
end)

12 comments

0

is it a local script

0

yes

0

RBXScriptSignal:wait() is deprecated, it is RBXScriptSignal:Wait()

0

wait() is deprecated??? so from now on I just use Wait()

0

i edited it

0

I cant add a click detector....

0

dont use a click detector

0

You can't change EnableMouseLockOption's value in a LocalScript unless you only want to change it for your player, if you want it to replicate to all clients then you need to use a RemoteEvent.

0

oh ok I removed EnableMouseLockOption, btw @stinkyest11 your script didnt work

0

What I said is also true for other parts of your script, including changing the CFrame of the UpperTorso, unless you don't want it to appear on everyone's screen.

0

@MythicalShade wait I thought only one players CFrame would change since its a local script

0

Only one player's CFrame will change with a local script, I mean that everyone will see that the player has moved, instead of only the player that moved seeing that he moved. (Sorry if it's confusing, but I'd look at my answer.)

2 answers

If you're using a LocalScript to handle the GUI stuff (which you have to), then changing EnableMouseLockOption = true won't actually have any effect to the server meaning it won't replicate to other clients due to FilteringEnabled. To fix this you need a RemoteEvent located in ReplicatedStorage and a Server Script located in ServerScriptService.

Local Script (just added on to what you had)

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local Event = game:GetService("ReplicatedStorage").RemoteEvent -- add a remoteevent object to replicated storage

local lore = player.PlayerGui.ChooseCharacter.Background.Zeus.Lore.TextLabel
local gui = player.PlayerGui.ChooseCharacter
local God = player.PlayerGui.ChooseCharacter.God
local button = player.PlayerGui.ChooseCharacter.Background.Zeus

button.MouseButton1Click:Connect(function()
    gui.Background.Visible = false
    lore.Visible = false
    God.Value = "Zeus"
    Event:FireServer()
end)

Server Script

local Event = game:GetService("ReplicatedStorage").RemoteEvent -- get event

Event.OnServerEvent:Connect(function(Player)
	game.StarterPlayer.EnableMouseLockOption = true
	Player.character.UpperTorso.CFrame = CFrame.new(182, 0.5, 39)  
end

If this doesn't work or you are confused let me know.

6 comments

0

I have 2 questions.

0

First, Whats the difference between your script and mine. And secondly ServerScripts are normal Scripts that go in Replicated Storage right?

0

First of all, your script is just a local script, which cannot make changes that replicate to other clients due to filtering enabled. In my scripts I use a remoteEvent to be able to replicate these changes to clients, which you should probably look into FilteringEnabled/RemoteEvents for. Also, ServerScripts are "normal Scripts", but they do not generally go into Replicated Storage.

0

They usually go into ServerScriptService. (Sorry characters got cut off)

0

ohhh ok thx for help

0

No problem, did the script work?

you can only use localplayer in a localscript. (assuming script is a child of the button) try on the local script

script.Parent.Activated:Connect(function(player)

script.Parent.RemoteEvent:FireServer()
end)

create a new remote event under the same parent as the script then create a new regular script

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
local character = player.CharacterAdded:wait()

local lore = player.PlayerGui.ChooseCharacter.Background.Zeus.Lore.TextLabel
local gui = player.PlayerGui.ChooseCharacter
local God = player.PlayerGui.ChooseCharacter.God

    gui.Background.Visible = false
    game.StarterPlayer.EnableMouseLockOption = true
    lore.Visible = false
    God.Value = "Zeus"

    character.UpperTorso.CFrame = CFrame.new(182, 0.5, 39)  
end)

7 comments

0

This is wrong. MouseButton1Click passes no parameters.

0

Also GUI events can only be handled from the client and not the server.

0

its a local script tho

0

I have a question, dont you need to have MouseButton1Click?

0

it didnt work

0

try the new edit mate

0

@stinkyest11 I tried the new edit and it didnt work

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