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

how do I make player dissapear button work on server side?

I have this gui button that when clicked makes player dissapear but i just realised it only works on client side, how do i make player invisible on server side?

Btw this is my current code that works perfectly on client side:

local button = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local activated = false

local function dissapear()
	if activated == true then
		local descendants = character:GetDescendants()
		activated = false
		for i, descendant in pairs(descendants) do
			if descendant:IsA("BasePart") then
				descendant.Transparency = 0
				character.Head.face.Transparency = 0
				humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
				humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.DisplayWhenDamaged
			end
		end
	else
		local descendants = character:GetDescendants()
		activated = true
		for i, descendant in pairs(descendants) do
			if descendant:IsA("BasePart") then
				descendant.Transparency = 1
				character.Head.face.Transparency = 1
				humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
				humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOn
			end
		end
	end
end



local function onButtonActivated()
	if activated == false then
		dissapear()
		character.HumanoidRootPart.Transparency = 1
		activated = true
		button.BackgroundColor3 = Color3.new(0.133333, 1, 0)
	else
		dissapear()
		character.HumanoidRootPart.Transparency = 1
		activated = false
		button.BackgroundColor3 = Color3.new(0.6, 0.6, 0.6)
	end
	
	
end

button.Activated:Connect(onButtonActivated)


1 answer

✓ Accepted answer

Make a RemoteEvent and fire it when the button gets clicked, copy and paste the code on a server side script that runs when the RemoteEvent gets fired

it looks similar to something like this (its recommended to make RemoteEvents in ReplicatedStorage):

local RS = game:GetService("ReplicatedStorage")

local invisible = false
local button = script.Parent:FindFirstChild("TextButton")

button.MouseButton1Click:Connect(function()
	if not invisible then
		RS.invisibleEvent:FireServer("Invisible")
		invisible = true
	else
		RS.invisibleEvent:FireServer("Visible")
		invisible = false
	end
end)

^ that should cover the client side part

and now you detect the event in the server script.

local RS = game:GetService("ReplicatedStorage")

RS.invisibleEvent.OnServerEvent:Connect(function(player, iRemote)
	if iRemote == "Invisible" then
		-- code to make player invisible
	elseif iRemote == "Visible" then
		-- code to make player visible again
	end
end)

you can just switch up what I put here with your own code which does exactly what you're looking for.

3 comments

0

Thanks

0

Wait but when i click the button everyone on the server gets invisible is there a way to check who clicked it?

0

the first keyword in the server script called 'player' tracks the localplayer

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