Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

attempt to index local 'object' (a number value)?

Asked by 5 years ago

I am getting this error while making a gun system.

script.Parent.DamageEvent.OnServerEvent:Connect(function(damage,object)
local human = object.Parent:FindFirstChild("Humanoid")
local gib = script.Gib:Clone()
gib.FX.Enabled = true
gib.CFrame = CFrame.new(object.CFrame.X,object.CFrame.Y,object.CFrame.Z)
game.Debris:AddItem(gib,0.35)
if human~=nil then
    human:TakeDamage(damage)
end
end)

Does anyone know how does that happen and how do you fix it??

0
The other script which is firing the server: script.Parent.DamageEvent:FireServer(dmg,target) xXRedPawnerXx -2 — 5y
0
Roblox adds the player that fired the remote as the first argument so damage will be the player and object will hold the damage. Just add an additional parameter in the function to hold the player object. User#5423 17 — 5y
0
Can you show that with a script? xXRedPawnerXx -2 — 5y
0
our goal is not to just fix your script, it's to explain what happend too. my answer will explain as good as kingdom did and will give you an answer starmaq 1290 — 5y
View all comments (2 more)
0
soo, it worked? starmaq 1290 — 5y
0
you seriously didnt check back yet.... starmaq 1290 — 5y

1 answer

Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 years ago

So, the :FireServer()function has thing where the 1st argument is automaticlly set to the localplayer. So pretty much if you're doing.

--Local
remote:FireServer(1235, true)
--Server
remote.OnServerEvent:Connect(function(number, bool)
print(number)
print(bool)
end)

Now this should technaclly print 1235 and true, because those are the values that we fired from the local script, but no actually, it will print the player's name, and then 1235. And that's because the 1st argument is always the player, even if you didn't set it to the player. The :FireServer() will set it as the 1st argument, and let's say if you got another argument that you see as the first one, it will be second, and all arguments will be moved by one. That's what happened wiht the script that I wrote. the number paramater was the player cuz that's always first, but number which was the 1st paramater became second. And that's exactly the problem with your script. You set dmg which is a number value as a first argument, and i'm assuming that the object is the player. since as we said player is always the first argument by default. dmg became the player instance, and the number value stored as dmg became the object argument.

So this should be your script.

    script.Parent.DamageEvent.OnServerEvent:Connect(function(player,dmg)
local human = player.Parent:FindFirstChild("Humanoid")
local gib = script.Gib:Clone()
gib.FX.Enabled = true
gib.CFrame = CFrame.new(player.CFrame.X,player.CFrame.Y,player.CFrame.Z)
game.Debris:AddItem(gib,0.35)
if human~=nil then
    human:TakeDamage(dmg)
end
end)

And don't forget to change the arguments in the local script. The player is set to first, and the damage is second.

0
and please im on a bit of a grind so can you upvote my answer ty :3 starmaq 1290 — 5y
0
and sorry for begging starmaq 1290 — 5y
0
btw change the object thing in the cframe line 05 starmaq 1290 — 5y
0
also it might not work out because im using the player, and you are probarly using another thing, so change that, by making the object you want the 3rd argument starmaq 1290 — 5y
Ad

Answer this question