This should fix it
what it does is Checks for nil
values: Ensure plr
and plr.Name
are not nil
before using them.
Server Script
local Remote2 = game.ReplicatedStorage.Remotes:WaitForChild("BlockVal")
local Remote3 = game.ReplicatedStorage.Remotes:WaitForChild("BlockType")
local ReplicatedStorage = game.ReplicatedStorage
local Blocks = ReplicatedStorage.Blocks
local CloneName = "Wood"
local Run = 0
local Names = script.Parent.Names
local PreNameCheck = "?ewrwer432r34r3r34r34r43r34r34r"
local TableFP = {}
local SurfaceVectors = {
Top = Vector3.new(0, 1, 0),
Bottom = Vector3.new(0, -1, 0),
Left = Vector3.new(-1, 0, 0),
Right = Vector3.new(1, 0, 0),
Front = Vector3.new(0, 0, -1),
Back = Vector3.new(0, 0, 1),
}
Remote.OnServerEvent:Connect(function(plr, Pos, MP)
task.wait()
if plr and plr.Name then
print("Player name received: " .. plr.Name)
local textLabel = game.ReplicatedStorage:FindFirstChild("TextLabel")
if textLabel then
textLabel.Text = plr.Name
print("TextLabel updated to: " .. plr.Name)
else
print("TextLabel not found in ReplicatedStorage.")
end
else
print("Invalid player object or player name is nil.")
end
if Names.Name1.Text == "sa0d43nofdbvb59vbbs[bfp3w[rbf5rw34bg9uv954w" and Names.Name2.Text ~= plr.Name and Names.Name3.Text ~= plr.Name and Names.Name4.Text ~= plr.Name and Names.Name5.Text ~= plr.Name and Names.Name6.Text ~= plr.Name and Names.Name7.Text ~= plr.Name and Names.Name8.Text ~= plr.Name and Names.Name9.Text ~= plr.Name and Names.Name10.Text ~= plr.Name and Names.Name11.Text ~= plr.Name and Names.Name12.Text ~= plr.Name and Names.Name13.Text ~= plr.Name and Names.Name14.Text ~= plr.Name and Names.Name15.Text ~= plr.Name then
Names.Name1.Text = plr.Name
PreNameCheck = plr.Name
elseif game.Players:FindFirstChild(plr.Name) == nil then
Names.Name1.Text = "sa0d43nofdbvb59vbbs[bfp3w[rbf5rw34bg9uv954w"
PreNameCheck = "sa0d43nofdbvb59vbbs[bfp3w[rbf5rw34bg9uv954w"
game.ReplicatedFirst.Names.Name1.Text = "sa0d43nofdbvb59vbbs[bfp3w[rbf5rw34bg9uv954w"
CloneName = "Wood"
end
if Names.Name1.Text ~= "sa0d43nofdbvb59vbbs[bfp3w[rbf5rw34bg9uv954w" and game.Players:FindFirstChild(plr.Name) ~= nil then
Remote2:FireClient(plr)
Remote3.OnServerEvent:Connect(function(plr, CN, RunSwitch)
task.wait()
if plr.Name ~= PreNameCheck then
-- Do nothing
elseif plr.Name == PreNameCheck then
if RunSwitch == nil then
-- Do nothing
else
Run = RunSwitch
end
CloneName = CN
end
end)
if Run == 1 then
local Cost = 15
if CloneName == "Bomb" then
Cost = 250
elseif CloneName == "Wood" then
Cost = 15
elseif CloneName == "Stone" then
Cost = 55
elseif CloneName == "Lava" then
Cost = 350
elseif CloneName == "Healer" then
Cost = 2500
elseif CloneName == "LightBulb" then
Cost = 175
end
if plr.leaderstats.Cash.Value >= Cost then
local Clone = game.ReplicatedStorage.Blocks:FindFirstChild(CloneName):Clone()
local surface = MP
local surfaceVector = SurfaceVectors[surface]
local adjustedX = Pos.X + surfaceVector.X
local adjustedY = Pos.Y + surfaceVector.Y
local adjustedZ = Pos.Z + surfaceVector.Z
Clone.Parent = game.Workspace.Block
Clone.Player.Text = plr.Name
Clone.Position = Vector3.new(math.round(adjustedX / 4) * 4, math.round(adjustedY / 4) * 4 + 2, math.round(adjustedZ / 4) * 4)
if Clone.Name == "Bomb" or Clone.Name == "Lava" or Clone.Name == "Healer" then
Clone.Part.Position = Vector3.new(math.round(adjustedX / 4) * 4, math.round(adjustedY / 4) * 4 + 3.5, math.round(adjustedZ / 4) * 4)
end
local CloneGTP = Clone:GetTouchingParts()
if #CloneGTP > 0 then
for i = 1, #CloneGTP do
if CloneGTP[i].Name ~= "Baseplate" then
Clone:Destroy()
end
end
end
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value - Cost
end
end
end
end)
Put in StarterPlayerScripts Local script
repeat wait() until game.ReplicatedStorage:WaitForChild("Remotes")
local BlockVal = game.ReplicatedStorage.Remotes:WaitForChild("BlockVal")
local BlockType = game.ReplicatedStorage.Remotes:WaitForChild("BlockType")
BlockVal.OnClientEvent:Connect(function(plr)
local NameCheck = script.Parent.Names.Name1.Text
local Player = game.Players.LocalPlayer
print(tostring(plr).." :NameCheck; Player: ") -- this print is to test if it's not nil
if Player.Name ~= NameCheck then
-- Do nothing
elseif Player.Name == NameCheck then
local BV = game.ReplicatedStorage.BlockVal
wait(0.1)
local SN = "Wood"
if BV.Value == 0 then
SN = "Bomb"
elseif BV.Value == 1 then
SN = "Wood"
elseif BV.Value == 2 then
SN = "Stone"
elseif BV.Value == 3 then
SN = "Lava"
elseif BV.Value == 4 then
SN = "Healer"
elseif BV.Value == 5 then
SN = "LightBulb"
end
local SV = game.ReplicatedStorage.SwitchVal
BlockType:FireServer(SN, SV.Value)
end
end)
StarterPlayerScripts local script
local PlaceRe = game.ReplicatedStorage.Remotes:WaitForChild("PlaceRe")
local BlockType = game.ReplicatedStorage.Remotes:WaitForChild("BlockType")
local Button = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local function Clicked()
local mouse = game.Players.LocalPlayer:GetMouse()
local MP = mouse.TargetSurface.Name
PlaceRe:FireServer(mouse.Hit.Position, MP)
end
mouse.Button1Down:Connect(Clicked)
Also, why are the Local scripts
all in one code?
Its easier to manage if its modular.