Is this a server script or a local script? If this is a server script, just make an if statement to make sure the player exists before running the rest of the code.
local plr = playerService:GetPlayerFromCharacter(char)
if plr then
-- rest of the code
end
If this doesnât fix the issue, your âcharâ variable might be nil.
Is âtextâ a TextLabel or a Value? I believe you are mentioning the TextLabelâs property âTextâ as the variable instead of the instance. And where is your Value located?
there is no âvalueâ of a text. you need to say âŚText = âŚText + 1
but your error isnât related to that. You are not giving a correct argument to function in first line, check what char is.
local Crystal = script.Crystal
local playerService = game:GetService("Players")
script.Crystal.Touched:Connect(function(char)
Crystal.Transparency = 1
Crystal.CanTouch = false
local plr = playerService:GetPlayerFromCharacter(char)
if plr then
local plr = playerService:GetPlayerFromCharacter(char)
local text = plr.PlayerGui.mainGui.Frame.TextLabel
local value = text:FindFirstChild("NumValue")
value.Value += 1
text.Text = value.Value
end
wait(5)
Crystal.Transparency = 0
Crystal.CanTouch = true
end)
just incase i missed something important heres my whole script
You should go client-side though so you donât need to use :GetPlayerFromCharacter() method. You could just use LocalPlayerâs character (clientâs character) and change the GUI.
local Crystal = script.Crystal
local playerService = game:GetService("Players")
script.Crystal.Touched:Connect(function(char)
Crystal.Transparency = 1
Crystal.CanTouch = false
local plr = playerService:GetPlayerFromCharacter(char.Parent)
if plr then
local text = plr.PlayerGui.mainGui.Frame.TextLabel
local value = text:FindFirstChild("NumValue")
value.Value += 1
text.Text = value.Value
end
wait(5)
Crystal.Transparency = 0
Crystal.CanTouch = true
end)
if not hitPart.Part.Parent:FindFirstChild("Humanoid") then
which isnât correct. There isnât any other part. I donât know whether itâs a typo or not, but also, he thought I solved his actual problem, yeah you do told him some more things to be fixed I guess but solution is just when your actual problem is solved, rest all more things given are good but actual problem should be solved. And you solved this problem, but when he marked as a solution, but normally we consider people giving answers first. I just recorrected @LeqenDzTR post, like doing some minor changes, but itâs his choice what he got worked. Itâs just your posts was good for some extra issues, you picked up the main thing, but it was after he marked as solution, also we shouldnât focus on solutions, we should focus on helping people which you did, indeed. Anyways, thanks.