Hello! I am trying to make a part on my character turn visible with a click of a GUI button.
while the script i have works, It is not Server-Sided and I need it to be! I know I need a Remote event and a server + client script, I just do not know how i would script the server side part.
I’ve tried to look around for answers but nothing I’ve found has really resembled my problem
here is my client script. (it may not be important but i am using a custom model!)
local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
playing = false
local function appear(object)
if object and object:IsA("Model") then
for index, part in pairs(object:GetChildren()) do
if part:IsA("MeshPart") then
part.Transparency = 0
end
end
end
end
local function dissapear(object)
if object and object:IsA("Model") then
for index, part in pairs(object:GetChildren()) do
if part:IsA("MeshPart") then
part.Transparency = 1
end
end
end
end
-- end
script.Parent.MouseButton1Click:connect(function()
local wingszom = character:FindFirstChild("zombie Wings")
local tail = character:FindFirstChild("zombie tail")
if playing == false then
playing = true
appear(wingszom)
appear(tail)
script.Parent.TextLabel.Text = "Hide Wings"
else
if playing == true then
playing = false
dissapear(wingszom)
dissapear(tail)
script.Parent.TextLabel.Text = "Show Wings"
end
end
end)
local RemoteEvent = game.ReplicatedStorage.YourRemoteEvent
--RemoteEvent2 is to get change from server to change button text
local RemoteEvent2 = game.ReplicatedStorage.YourRemoteEvent2
script.Parent.MouseButton1Click:connect(function()
--this is to fire your click to the server
RemoteEvent:FireServer()
end)
RemoteEvent2.OnClientEvent:Connect(function(playing)
if playing == false then
playing = true
script.Parent.TextLabel.Text = "Hide Wings"
else
if playing == true then
playing = false
script.Parent.TextLabel.Text = "Show Wings"
end
end)
server side:
local RemoteEvent = game.ReplicatedStorage.YourRemoteEvent
--RemoteEvent2 is to get change from server to change button text
local RemoteEvent2 = game.ReplicatedStorage.YourRemoteEvent2
--your functions
local function appear(object)
if object and object:IsA("Model") then
for index, part in pairs(object:GetChildren()) do
if part:IsA("MeshPart") then
part.Transparency = 0
end
end
end
end
local function dissapear(object)
if object and object:IsA("Model") then
for index, part in pairs(object:GetChildren()) do
if part:IsA("MeshPart") then
part.Transparency = 1
end
end
end
end
--when click event fired
RemoteEvent.OnServerEvent:Connect(function(player)
local character = player.CharacterAdded:Wait()
repeat task.wait() until character.Parent == workspace
local hum = character:WaitForChild("Humanoid")
playing = false
local wingszom = character:FindFirstChild("zombie Wings")
local tail = character:FindFirstChild("zombie tail")
if playing == false then
playing = true
RemoteEvent2.FireClient(player, playing)
appear(wingszom)
appear(tail)
else
if playing == true then
playing = false
RemoteEvent2.FireClient(player, playing)
dissapear(wingszom)
dissapear(tail)
end
end
end
oh! sorry I didn’t have time to check my solution and made some typo mistakes. Copy now and it should work-
client side:
local RemoteEvent = game.ReplicatedStorage.YourRemoteEvent
--RemoteEvent2 is to get change from server to change button text
local RemoteEvent2 = game.ReplicatedStorage.YourRemoteEvent2
script.Parent.MouseButton1Click:connect(function()
--this is to fire your click to the server
RemoteEvent:FireServer()
end)
RemoteEvent2.OnClientEvent:Connect(function(playing)
if playing == false then
playing = true
--I think you should change text button text intead of texl label text. But if you want you can add it back
script.Parent.Text = "Hide Wings"
elseif playing == true then
playing = false
script.Parent.Text = "Show Wings"
end
end)
server side:
game.Players.PlayerAdded:Connect(function(player)
local playing = Instance.new("BoolValue", player)
playing.Name = "Playing"
playing.Value = false
end)
local RemoteEvent = game.ReplicatedStorage.YourRemoteEvent
--RemoteEvent2 is to get change from server to change button text
local RemoteEvent2 = game.ReplicatedStorage.YourRemoteEvent2
--your functions
local function appear(object)
if object and object:IsA("Model") then
for index, part in pairs(object:GetChildren()) do
if part:IsA("MeshPart") then
part.Transparency = 0
end
end
end
end
local function dissapear(object)
if object and object:IsA("Model") then
for index, part in pairs(object:GetChildren()) do
if part:IsA("MeshPart") then
part.Transparency = 1
end
end
end
end
--when click event fired
RemoteEvent.OnServerEvent:Connect(function(player)
local character = player.Character
repeat task.wait() until character.Parent == workspace
local hum = character:WaitForChild("Humanoid")
local playing = player.Playing
local wingszom = character:FindFirstChild("zombie Wings")
local tail = character:FindFirstChild("zombie tail")
if playing.Value == false then
playing.Value = true
RemoteEvent2:FireClient(player, playing.Value)
appear(wingszom)
appear(tail)
elseif playing.Value == true then
playing.Value = false
RemoteEvent2:FireClient(player, playing.Value)
dissapear(wingszom)
dissapear(tail)
end
end)