script.Parent.Touched:Connect(function(hit) local player = game:GetService("Players") if hit then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.leaderstats.Coin.Value >= script.Parent.Requirement.Value then player.leaderstats.Coin.Value -= script.Parent.Requirement.Value for i,v in pairs(workspace.MinimapObjects.Maps.DesertMap:GetChildren()) do v.Transparency = 0.75 v.CanCollide = false script.Parent.SurfaceGui.TextLabel.Visible = false end if player.leaderstats.Coin.Value < script.Parent.Requirement.Value then player.PlayerGui.Status.NotEnoughMoney.Visible = true script.Parent.SurfaceGui.TextLabel.Visible = true wait(1) player.PlayerGui.Status.NotEnoughMoney.Visible = false end end end end)
Please consider saying at what line this error fires.
I guess this is happening because you're not checking if part "hit" you're touching is actually part of character. You're just checking if hit exists. To fix it you need to check if hit is actually part of a character.
you can do it like this:
if hit.Parent:FindFirstChild("Humanoid") ~= nil then: -- hit is a part of character and hit.Parent is character itself. end
ALSO!!! Please check if player exists after getting him from :GetPlayerFromCharacter() method.
if player then: end
Also this can happen because you're making 2 variables with same name "player"
local player = game:GetService("Players") -- and local player = game.Players:GetPlayerFromCharacter(hit.Parent)