Hello! I am fairly new to scripting, but I have pretty a knowledgeable understanding of it so far. I made a key tool that players can pick up successfully with a script I made. I now want to change that into a script that gives each player (client) the key once and then makes the key unobtainable for that individual player (client) forever until they rejoin. I am still teaching myself ‘Remote Events’ and ‘Remote Functions’ as I have less knowledge with those concepts. I don’t know if I should even use those for this situation.
Brief Video that shows what I’m trying to do but per client:
My Goal: Make a one-time-use client tool giver: Gives the player the key that clicked the key once and disappears only for that player (client) but the key is still there for other players (clients) who haven’t yet clicked the key
My issue is I can’t figure out the best way to execute this. Whether it be through remote events, remote functions, or something else. I can’t get it to work with remote events (I could be doing it wrong). I’ve heard tool givers don’t work with local scripts, I also test that statement and it is true.
I’ve tried digging around on the Developer Forums and Hub in search of a solution to this, I tried FireClient() which sends a request to the server to execute something from the client which didn’t work.
--This was my original code which works fine in a normal script, but it's global so only one player can get a key, I know how to make it so more player can get the key. However, I'd prefer that each client will only click and see the key once and then they have to rejoin in order to see and obtain the key again.
local KeyModel = game.Workspace.Clickables.DoorKey.Key.DoorKeyModel
local DoorKey = game.ServerStorage.DoorKey
local CD = game.Workspace.Clickables.DoorKey.Key.ClickBox.ClickDetector
game.Workspace.Clickables.DoorKey.Key.ClickBox.ClickDetector.MouseClick:Connect(function(playerWhoClicked)
if not playerWhoClicked.Backpack:FindFirstChild("DoorKey") then --If the player doesn't have the key in their inventory then do the following
CD.MaxActivationDistance = 0
KeyModel.Transparency = 1
DoorKey:Clone()
DoorKey.Parent = playerWhoClicked.Backpack
end
end)
----------------------------------------------------------------------------------------------------------------------------------------
--This is what I tried, but failed:
--Script
game.Workspace.Clickables.DoorKey.Key.ClickBox.ClickDetector.MouseClick:Connect(function(player)
game.ReplicatedStorage.PlayerGotKey:FireClient(player)
end)
--Local Script
local KeyModel = game.Workspace.Clickables.DoorKey.Key.DoorKeyModel
local DoorKey = game.ServerStorage.DoorKey
local CD = script.Parent.Key.ClickBox.ClickDetector
local function PlayerGotKey()
script.Parent.Key.ClickBox.ClickDetector.MouseClick:Connect(function(playerWhoClicked)
if not playerWhoClicked.Backpack:FindFirstChild("DoorKey") then
CD.MaxActivationDistance = 0
KeyModel.Transparency = 1
DoorKey:Clone()
DoorKey.Parent = playerWhoClicked.Backpack
end
end)
end
game.ReplicatedStorage.PlayerGotKey.OnClientEvent:Connect(PlayerGotKey)
I’d rather receive feedback or a better understanding of how I can accomplish this rather than someone just re-scripting this. Thanks for your help.