Hey, so I was writing code for a leaderstats wall, then I encountered a error, I have tried fixing it with no luck. If anyone knows why, let me know.
Here is the code:
ServerScript (Inside Part):
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
if not char then
return – Exit the function if hit.Parent is nil
end
local world = workspace.World1
local barrier = script.Parent.Parent:WaitForChild("Barrier")
local humanoid = char:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
if humanoid and player and player.leaderstats then
local minedValue = player.leaderstats:FindFirstChild("Mined")
if minedValue and minedValue:IsA("NumberValue") and minedValue.Value >= script.Parent.Price.Value then
if world and barrier then
print("sent")
game.ReplicatedStorage.RemoteEvents.touchedWall:FireClient(player, world.Name, barrier.Name)
else
print("World or barrier not found.")
end
else
print("Insufficient mined value.")
end
end
end)
Client Script Inside StartPlayerScripts:
game.ReplicatedStorage.RemoteEvents.touchedWall.OnClientEvent:Connect(function(player, world, wall )
local worldFound = workspace:FindFirstChild(world)
local WallFound = worldFound:WaitForChild(wall)
if worldFound then
print("Founed")
end
end)