So, I’ve made a system in which the player spawns with an instance value attached to them. I have this set up to where the player is able to access certain doors depending on the value they carry. Currently, I’m struggling to acquire the player value through a server script after the player interacts with a button on a computer via a RemoteEvent
. While the code I currently have works with the doors in my world- I run into this error:
So I was wondering if it would be better to use an Attribute
or something, or is this a simple fix that I’m just simply overlooking? Here is the code from my server script located under ServerScriptService
:
-- Get services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Get events
local events = ReplicatedStorage.Events
local selectionEvent1 = events.SelectionEvent1
-- Function to assign base value to players upon joining
Players.PlayerAdded:Connect(function(player)
-- Value settings
local value = Instance.new("NumberValue")
value.Name = "Selection"
value.Value = 0
value.Parent = player
end)
selectionEvent1.OnServerEvent:Connect(function(player)
-- Get selection value
local selection = player.Character:WaitForChild("Selection")
selection.Value = 1
print("Value changed")
end)