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)
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.
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)