Getting Character from an Server-Side Script

Server-Side Script:

local Base = script.Parent
local Reader1 = Base.Reader
local Reader2 = Base.Reader2
local Frame = Base.Frame

local Door = Base.Door1
local ExD = Base.Ex1
local Door2 = Base.Door2
local ExD2 = Base.Ex2
local Bool = Base.Opened
local Prompt = Reader1.P1.ProximityPrompt
local Prompt2 = Reader1.P2.ProximityPrompt
local Prompt1e = Reader2.P1.ProximityPrompt
local Prompt2e = Reader2.P2.ProximityPrompt
local Light = Reader1.Light
local Light1 = Reader2.Light

-- Sound
local Accept = Frame.Accepted
local Denied = Frame.Refused
local OpenS = Frame.Open

-- Clearance
local clearance = {
	"[CCI] CID - III",
	"[CCI] CID - IV",
	"[CCI] CID - V",
	"[CCI] Combative Card",
	"[GOI] CID - III",
}
local PH = {
	"[CCI] CID - 0",
	"[CCI] CID - I",
	"[CCI] CID - II",
	"[GOI] CID - II",
}

-- Tween
local countdown = 3
local TS = game:GetService("TweenService")
local TInfo = TweenInfo.new(countdown)

local Door2Open = {CFrame = ExD2.CFrame}
local Door1Open = {CFrame = ExD.CFrame}
local Door1Close = {CFrame = Door.CFrame}
local Door2Close = {CFrame = Door2.CFrame}
local TOpen1 = TS:Create(Door, TInfo, Door1Open)
local TClose1 = TS:Create(Door, TInfo, Door1Close)
local TOpen2 = TS:Create(Door2, TInfo, Door2Open)
local TClose2 = TS:Create(Door2, TInfo, Door2Close)

-- Functions

local function acceptAccess()
	print("Access Permitted")
	Bool.Value = true
	Prompt.Enabled = false
	Prompt2.Enabled = false
	Prompt1e.Enabled = false
	Prompt2e.Enabled = false
	Accept:Play()
	Light.BrickColor = BrickColor.new("Lime green")
	Light.Material = Enum.Material.Neon
	Light1.BrickColor = BrickColor.new("Lime green")
	Light1.Material = Enum.Material.Neon
	OpenS:Play()
	TOpen1:Play()
	TOpen2:Play()
	wait(countdown)
	Bool.Value = false
	Prompt.Enabled = true
	Prompt2.Enabled = true
	Prompt1e.Enabled = true
	Prompt2e.Enabled = true
	Light.BrickColor = BrickColor.new("White")
	Light.Material = Enum.Material.Ice
	Light1.BrickColor = BrickColor.new("White")
	Light1.Material = Enum.Material.Ice
	OpenS:Play()
	TClose1:Play()
	TClose2:Play()
end

local function refuseAccess()
	print("Access Denied")
	Bool.Value = true
	Prompt.Enabled = false
	Prompt2.Enabled = false
	Prompt1e.Enabled = false
	Prompt2e.Enabled = false
	Denied:Play()
	Light.BrickColor = BrickColor.new("Really red")
	Light1.BrickColor = BrickColor.new("Really red")
	wait(1)
	Bool.Value = false
	Prompt.Enabled = true
	Prompt2.Enabled = true
	Prompt1e.Enabled = true
	Prompt2e.Enabled = true
	Light.BrickColor = BrickColor.new("White")
	Light1.BrickColor = BrickColor.new("White")
end

local function AcessHandler(player)
	if not Bool.Value then
		local PermittedIten = false
		local DeniedItem = false
		for _, item in pairs(player.Backpack:GetDescendants()) do
			if table.find(clearance, item.Name) then
				PermittedIten = true
			elseif table.find(PH, item.Name) then
				DeniedItem = true
			end
		end
		if PermittedIten then
			acceptAccess()
		elseif DeniedItem then
			Prompt.Enabled = false
			Prompt2.Enabled = false
			Prompt1e.Enabled = false
			Prompt2e.Enabled = false
			refuseAccess()
			Prompt.Enabled = true
			Prompt2.Enabled = true
			Prompt1e.Enabled = true
			Prompt2e.Enabled = true
		else
			Prompt.Enabled = false
			Prompt2.Enabled = false
			Prompt1e.Enabled = false
			Prompt2e.Enabled = false
			refuseAccess()
			Prompt.Enabled = true
			Prompt2.Enabled = true
			Prompt1e.Enabled = true
			Prompt2e.Enabled = true
		end
	end
end

-- Script

Prompt.Triggered:Connect(AcessHandler)
Prompt1e.Triggered:Connect(AcessHandler)

I know it’s impossible to detect the character from an server side, but still I need it so I can track the tools inside character as when you put the tool in your hand, it will go to your character. My script only detects the itens if they’re inside backpack but when they picked the tool, it will not detect anymore.

Any way to resolve this situation?

8 Likes

player.Character will give you the character

5 Likes

if its single player, you can write another script to put the path to the player as the value of an ObjectValue when they join the game. if not then if you can tell me what you need it for in the script and I can show you how to find it for that purpose

3 Likes

That would be for LocalScript.

3 Likes

It’s multiplayer
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

1 Like

No player.Character still works on the server. The only thing that doesn’t work on the server is Players.LocalPlayer.

5 Likes

Hmm, i always though that getting character would be impossible inside server side script

3 Likes

So resumily

for _, item in pairs(player.Backpack:GetDescendants() or player.Character:GetDescendants()) do

This should work

2 Likes

You can’t use or with two tables like that.

2 Likes

How I would do then?wwwwwwwwwwww

2 Likes

You either somehow gotta add the two tables together, or run them through separate for in pairs loops.

It looks like you are doing a keycard door of sorts. Wouldn’t it be more realistic if you had to hold the keycard anyways?

1 Like

It’s quite eays to get the character from a server sided script.
Prompt.Triggered passes the player object like so:

prompt.Triggered:Connect(function(player)
    local character = player.Character
end)

Tools are either parented to the Character when equipped, or to the Backpack when unequipped

local tool = player.Backpack:FindFirstChild("myTool") or player.Character:FindFirstChild("myTool")
1 Like

It would, but it wouldn’t cause gameplay? i mean, having to change the keycard to open a door while in a combat situation

It would make more sense than the keycard reader so to speak detecting it in your backpack.

There is more than one item to trigger the door

1 Like

What do you mean? Like are there different items or do you need many to open one single door?

1 Like

Yeah, I mean, that’s true maybe I’ll change.

1 Like

There are many different items that can open the door, no need have every one. Just one of them it’s sufficient

1 Like

Yeah so if it’s enough with one keycard per door, you should require the player to hold it in their hand.

Yeah, I just though of that as that could benefit the combat. I’m doing an portuguese/brasilian SCPF so that’s why i needed this