This is the code, in principle I do not see that the UserId of the local player is saved in the value of: ReplicatedStorage.Players.HitmanCrime.Player
The script is in a LocalScript located inside a ProximityPrompt.
In principle, the error is that when activating the ProximityPrompt, the value of the UserId of the local player is not saved.
local proximityPrompt = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local l = ReplicatedStorage.Players.HitmanCrime
local localPlayer = Players.LocalPlayer
local player1 = l.Player
proximityPrompt.Triggered:Connect(function()
player1.Value = localPlayer.UserId
end)
I moved it to ServerScriptService, then tried putting it in StarterPlayerScripts, but it still doesnât save:
local part = game.Workspace["Part to CRIME1"]
local proximityPrompt = part.ProximityPrompt
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local l = ReplicatedStorage.Players.HitmanCrime
local localPlayer = Players.LocalPlayer
local player1 = l.Player
proximityPrompt.Triggered:Connect(function()
player1.Value = localPlayer.UserId
end)
Itâs a quite easily solution i think based on the details you gave. Modifying a value of an int value object will only keep it like that during game session. or while the player is inside the game. These values only good for some temporarly value holder. if you want to save data for longer periods or for later on usages then use datastores instead.
Make sure that the ReplicatedStorage.Players.HitmanCrime.Player value exists and is a StringValue or IntValue type. If it doesnât exist, you can create it using Instance.new(âStringValueâ) or Instance.new(âIntValueâ)
Verify that the part variable is correctly referencing the part in your game that has the ProximityPrompt. You can do this by printing the part variable to the output and checking if it is the expected part
Check if the proximityPrompt object has the Triggered event connected to the provided function. You can do this by printing the proximityPrompt.Triggered event to the output and checking if it is connected to the function.
Ensure that the local player variable is correctly referencing the local player. You can print the localPlayer variable to the output and check if it is the expected Player object.
btw,you used Players.LocalPlayer in a localscript if I understood ok, right?
you cant use localscripts in SERVERSCRIPSERVICE,like the name says, SERVERSCRIPTSERVICE
Localscripts works ONLY for client,and Script for all clients,try putting the code in a localscript in a StarterGUI,StarterPlayeScripts,etc. but NOT Workpspace ServerScriptService or ReplicatedFirst/Storage
Workspace.Part to CRIME1.ProximityPrompt.Script:12: attempt to index nil with âUserIdâ
local proximityPrompt = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local l = ReplicatedStorage.Players.HitmanCrime
local localPlayer = Players.LocalPlayer
local player1 = l.Player
proximityPrompt.Triggered:Connect(function()
player1.Value = localPlayer.UserId
print("Proximity Found")
end)
The error means that LocalPlayer doesnât exist. You canât get LocalPlayer on a server script, instead get the player through the Triggered event:
proximityPrompt.Triggered:Connect(function(playerTriggered) -- player who triggered the prompt
player1.Value = playerTriggered.UserId
print("Proximity Found")
end)
-- you must put where the ProximityPrompt is.
local Part = workspace:WaitForChild("Part")
local proximityPrompt = Part:WaitForChild("ProximityPrompt")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local l = ReplicatedStorage:WaitForChild("Players"):WaitForChild("HitmanCrime")
local player1 = l.Player -- I guess this is a number value right?
proximityPrompt.Triggered:Connect(function()
player1.Value = localPlayer.UserId
print("Proximity Found")
end)
Because the local ReplicatedStorage = game:GetService("ReplicatedStorage") looks like a Client script but client scripts localScripts cant run in Workspace.
15:49:19.834 Proximity Found - Cliente - LocalScript:13
15:49:19.849 Workspace.Part to CRIME1.ProximityPrompt.Script:12: attempt to index nil with âUserIdâ
In the error they provided I noticed the script is named Script so I think that theyâre using a server Script by mistake instead of a LocalScript, and LocalPlayer is nil when used in a server script