I need help with this keyCard event Script

Alright so basically im trying to make a script so that it puts a keycard in the player’s inventory when they click on a police officer that i added to the baseplate. I put a click detector in the police model and a remote even in the workspace. I used a local script for click, and a regular script in the remote event. The part where I need help is in the regular script.

Here is the local script:
image

Here is the regular script:
image

Sorry if I just wrote some random codes in the script. Im new to scripting so I dont know much. I thought that if I just add it into the starter pack then I will get the item in my inventory, but it didnt work.

1 Like

You can put the keycard tool in replicated storage. And do
ClickDetector.MouseClick:Connect(function()
game.ReplicatedStorage.KeyCard:Clone().Parent = player:WaitForChild(“Backpack”)
replace KeyCard with your tool name

ohh ok thanks for the help i didnt know how to do this

and btw whats the difference between replicated storage and server storage?

I think, server storage can only be accessed by the server.

You need to do sanity check, to check if the action was legitimate.

it says player is an unknown global

You can’t just clone it to player, it’ll equipped locally and nobody else can see it except yourself, fire it on server.

i did the FireServer command in the local script

im trying to do the one like jailbreak

The event that you fired must match on regular script.
Example

-- local script
local ClickDetector = game.Workspace.PoliceOfficer.ClickDetector

ClickDetector.MouseClick:Connect(function()
game.Workspace.MyClickDetectorEvent:FireServer()
end)


-- regular script

game.Workspace.MyClickDetector.OnServerEvent:Connect(function(player)

local Backpack = player:FindFirstChild("Backpack")
if Backpack then
-- clone your tool to backpack
end

end)

Sorry I’m on Mobile.

ok thanks

Summary

30 Charactersnnxwbhjwb wb