its cause the touching parts parent might not be a character
script.Parent.Touched:Connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent) -- get the player
if player then -- check if the player exists
-- rest of the script
end
end)
Also if its in a local script then it has to be a child of either the player or the character to run I think
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
script.Parent.Parent.Part.BillboardGui.TextBox.Text = "what"
local hasOil = Instance.new("IntValue")
hasOil.Name = "touchedOil"
hasOil.Parent = player
hasOil.Value = player.UserId
--game.ReplicatedStorage.oiltouched:FireServer()
end
end
end)
game.Players.LocalPlayer is not valid in server scripts, you can get the player instance which touched the part by doing what I did in the above additionally you were attempting to assign an integer value (user ID) to an ObjectValue instance which wouldn’t work, I’ve switched that for an IntValue instance.
What it doesn’t do is everything, what it’s supposed to do is make a StringValue and parent it to the player.
I thought of also using variables but I have to only use it once.
local part = script.Parent
local player = game.Players.LocalPlayer
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
script.Parent.Parent.Part.BillboardGui.TextBox.Text = "what"
local hasOil = Instance.new("IntValue")
hasOil.Name = "touchedOil"
hasOil.Parent = player
hasOil.Value = player.UserId
--game.ReplicatedStorage.oiltouched:FireServer()
end
end)
This will work as a local script, on an additional note you mention you wanted to use a StringValue instance but used an ObjectValue instance instead.
local hasOil = Instance.new("StringValue")
hasOil.Value = tostring(player.UserId)
You can use the above instead of an IntValue instance if necessary.