i have a problem where a tool i made is not working when you play like a normal user, it only works in Roblox studio
--This script is a normal script --the parent is a tool witch has a child called Handle --tools parent is inside starterPack
-- script made by trommestian03 with help from youtube while game.Players.LocalPlayer == nil do game.Players:GetPropertyChangedSignal('LocalPlayer'):wait() end local player = game.Players.LocalPlayer --getting player print(player.name) local mouse = player:GetMouse() --getting mouse local mtarget --getting mouse target local down local holding = script.Parent.holding local sb --selectionBox local dummyblock --dummblock test local ready = false --setting debounce local tool = script.Parent --getting tool tool.Activated:connect(function() ready = true print("hello") end) tool.Unequipped:connect(function() ready = false end) function clickObj() if mouse.Target ~= nil and mouse.Target.Name ~= "Baseplate" then -- moving and spawning a selectionBox if ready then mtarget = mouse.Target print(mtarget) mtarget.Anchored = true mouse.TargetFilter = mtarget print(mouse.TargetFilter) down = true holding.Value = true local selectionBox = Instance.new("SelectionBox") selectionBox.Adornee = mtarget selectionBox.Color3 = Color3.new(1,0,0) selectionBox.Parent = mtarget sb = selectionBox end end end mouse.Button1Down:connect(clickObj) -- testing for mouse butto press function mouseMove() -- making block follow the mouse if down and mtarget then local posX,posY,posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z --dummyblock.Position = Vector3.new(posX,posY,posZ) local fposX = math.floor(posX) local fposY = math.floor(posY) local fposZ = math.floor(posZ) mtarget.Position = Vector3.new(fposX,fposY,fposZ) end end mouse.Move:connect(mouseMove)
The mistake is made at line 4, serverscripts do not have a 'localplayer' only clients do.
To get the player is pretty easy as you know the tool is located inside the player so you can simply use
script.Parent -- Handle
script.Parent.Parent -- Tool
script.Parent.Parent.Parent -- Backpack
script.Parent.Parent.Parent.Parent -- Player
Another problem would be the mouse as mouse is only available for the client too, I would recommend making remote events