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

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

Asked by 5 years ago

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)

0
is it a local script User#23365 30 — 5y
0
yes turbomegapower12345 48 — 5y
0
RBXScriptSignal:wait() is deprecated, it is RBXScriptSignal:Wait() User#19524 175 — 5y
0
wait() is deprecated??? so from now on I just use Wait() turbomegapower12345 48 — 5y
View all comments (8 more)
0
i edited it stinkyest11 78 — 5y
0
I cant add a click detector.... turbomegapower12345 48 — 5y
0
dont use a click detector stinkyest11 78 — 5y
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. MythicalShade 420 — 5y
0
oh ok I removed EnableMouseLockOption, btw @stinkyest11 your script didnt work turbomegapower12345 48 — 5y
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. MythicalShade 420 — 5y
0
@MythicalShade wait I thought only one players CFrame would change since its a local script turbomegapower12345 48 — 5y
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.) MythicalShade 420 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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.

0
I have 2 questions. turbomegapower12345 48 — 5y
0
First, Whats the difference between your script and mine. And secondly ServerScripts are normal Scripts that go in Replicated Storage right? turbomegapower12345 48 — 5y
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. MythicalShade 420 — 5y
0
They usually go into ServerScriptService. (Sorry characters got cut off) MythicalShade 420 — 5y
View all comments (2 more)
0
ohhh ok thx for help turbomegapower12345 48 — 5y
0
No problem, did the script work? MythicalShade 420 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
This is wrong. MouseButton1Click passes no parameters. User#19524 175 — 5y
0
Also GUI events can only be handled from the client and not the server. User#19524 175 — 5y
0
its a local script tho User#23365 30 — 5y
0
I have a question, dont you need to have MouseButton1Click? turbomegapower12345 48 — 5y
View all comments (3 more)
0
it didnt work turbomegapower12345 48 — 5y
0
try the new edit mate stinkyest11 78 — 5y
0
@stinkyest11 I tried the new edit and it didnt work turbomegapower12345 48 — 5y

Answer this question