Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Mouse.Target Local Script Giving Expected Near Error?

The script is not working, and is giving me this error Workspace.Player1.LocalScript:8: 'do' expected near 'game'

player = game.Players.LocalPlayer
character = game.Players.LocalPlayer.Character
gun = character:findFirstChild("Rifle")
mouse = player:GetMouse()

mouse.Button1Down:connect(function()
function getModel(raw)
for _,__ in next game.Workspace:children'' do
if raw:IsDescendantOf(__) then
return __;
end;
end;
return raw;
end;

local success,hum = pcall(function() return getModel(mouse.Target).Humanoid end);
hum.Health = hum.Health -15

end)

1 answer

children requires (), not ''. Also, children is deprecated, use GetChildren() instead.

4 comments

0

I still get the same error of do expected near 'game'

0

try in next (workspace:GetChildren()) do (with the extra ()'s on the outside.)

0

ok, thats fixed but now i get the error of "Workspace.Player1.LocalScript:17: attempt to perform arithmetic on field 'Health' (a nil value)"

0

pcall returns 2 values by default, succes state and error. do: local succes,error,value = pcall(function() OR local succes,error = pcall(value = function()

This discussion is preserved as it was. New answers, comments, and votes are closed.