The error shows up at line 11 (The clicked function) It works in studio but not ingame. I tried waiting for the mouse but it just waits infinitely. The error that shows up (without the waiting) is "attempt to index local 'mouse' (a nil value)". I've checked and everything seems to be fine. when I changed mouse = player:GetMouse() to mouse = player (thinking maybe player was already the mouse), it said: Hit is not a part of Player.
part = script.Parent.PrimaryPart
mouseClicked = false
partMoving = false
collision = false
isincollision = false
originalcolor = {}
outOfBounds = false
function clicked(player)
mouse = player:GetMouse()
playerSlot = PlayerSlot(player)
for i,v in pairs(script.Parent:GetChildren()) do
local increment = 0
if v.ClassName == "Part" then
increment = increment+1
table.insert(originalcolor, v.BrickColor)
end
end
if mouseClicked == false then
mouseClicked = true
if partMoving == false then
partMoving = true
wait()
mouseClicked = false
MovePart(player)
else
wait()
mouseClicked = false
PlacePart(player)
end
end
end
function RoundUp(number)
local roundNumber = number-(number%0.5)
return roundNumber
end
function MovePart(player)
local mouse = player:GetMouse()
while partMoving == true do
script.Parent:SetPrimaryPartCFrame(CFrame.new((RoundUp(mouse.Hit.p.x)), script.Parent.PrimaryPart.CFrame.Y, (RoundUp(mouse.Hit.p.Z))))
wait()
end
end
function PlacePart(player)
local mouse = player:GetMouse()
if isincollision == false then
if outOfBounds == false then
partMoving = false
end
end
end
script.Parent.PrimaryPart.Changed:connect(function()
for i,modelpart in pairs(script.Parent:GetChildren()) do
if modelpart.ClassName == "Part" then
for i,part in pairs(modelpart:GetTouchingParts()) do
if part.Parent ~= script.Parent then
if collision == false then
collision = true
end
end
end
end
end
if collision ~= false then
isincollision = true
for i,v in pairs(script.Parent:GetChildren()) do
if v.ClassName == "Part" then
if v.BrickColor ~= BrickColor.new("Really red") then
v.BrickColor = BrickColor.new("Really red")
v.Transparency = 0.5
end
end
end
else
isincollision = false
local increment = 0
if outOfBounds == false then
for i,v in pairs(script.Parent:GetChildren()) do
if v.ClassName == "Part" then
increment = increment+1
local color = tostring(originalcolor[increment])
if v.BrickColor == BrickColor.new("Really red") then
v.BrickColor = BrickColor.new(color)
v.Transparency = 0
end
end
end
end
end
collision = false
end)
function PlayerSlot(player)
for i,v in pairs(game.Workspace.Slots:GetChildren()) do
if v.Slot_Owner.Value == player.Name then
print(v)
return v
end
end
end
script.Parent.PrimaryPart.Changed:connect(function()
local partSize = script.Parent.PrimaryPart.Size
local partPos = script.Parent.PrimaryPart.CFrame
local slotPosX = playerSlot.slot.Position.X
local slotPosZ = playerSlot.slot.Position.Z
local slotSizeX = playerSlot.slot.Size.X
local slotSizeZ = playerSlot.slot.Size.Z
local oneOutOfBounds = false
if oneOutOfBounds == false then
if partPos.X + partSize.X/2 > slotPosX+slotSizeX/2 then
oneOutOfBounds = true
elseif partPos.X - partSize.X/2 < slotPosX-slotSizeX/2 then
oneOutOfBounds = true
end
end
if oneOutOfBounds == false then
if partPos.Z + partSize.Z/2 > slotPosZ+slotSizeZ/2 then
oneOutOfBounds = true
elseif partPos.Z - partSize.Z/2 < slotPosZ-slotSizeZ/2 then
oneOutOfBounds = true
end
end
if oneOutOfBounds == true then
outOfBounds = true
for i,v in pairs(script.Parent:GetChildren()) do
if v.ClassName == "Part" then
if v.BrickColor ~= BrickColor.new("Really red") then
v.BrickColor = BrickColor.new("Really red")
v.Transparency = 0.5
end
end
end
else
outOfBounds = false
end
end)
script.Parent.ClickDetector.MouseClick:connect(clicked)

1 comment
Got it, let me try that right now. I thought it was that but wanted to make sure because I didn't want to do un needed programming. I've restarted this script 3 times because some things weren't the way I wanted them to be lol.