Since I Destroy Food (while eating) from the Server, the Destroy method doesn’t work anymore, it throws me an error: Error while firing a new event (event 7) from Leolol_DB Custom error ServerScriptService.EventService:32: attempt to call method ‘Destroy’ (a nil value) The error
Her’s the line that doesn’t work:
Data[2]:Destroy()
Data[2] is the object to destroy (because it was eaten)
The line that send the Data
NewEvent:FireServer(7,{Nut[ObjNum],Object})
--NewEvent is the Event's Name, 7 is for the eating event
--Nut = {48,32,24,16} , ObjNum is the Food's number (1 to 4), Object is the Food (Model) to destroy :)
The event (NewEvent) is firing correctly (the Server is adding the food’s nutrition to the food bar but when Data[2]:Destroy() is reached, it throw an error
If you need more informations to resolve this,: Reply!
It’s a picture of the update of Becants 0.0.9
Before, the Script with Destroy method was in each Food-things…
Now, it’s only ONE LINE of a script that do the same thing
But this line don’t work
So, placing print(typeof(Data[2]))directly before the throwing Destroy call outputs ‘Instance’? I need you to verify this by actually doing it and telling me the result.
It outputs: MeatyThing (it’s the pink food that I selected) Error while firing a new event (event 7) from Leolol_DB ServerScriptService.EventService:32: attempt to call method ‘Destroy’ (a nil value)
Oh! I forgot typeof!
String WUT??? Error while firing a new event (event 7) from Leolol_DB ServerScriptService.EventService:32: attempt to call method ‘Destroy’ (a nil value)
The issue is that Data[2] is a string, not an Instance. You’re trying to call the Destroy method of a string, when no such method exists. Make sure you’re sending the instance itself to the server, and not the instance’s name.
If the client changes the string to an instance after sending the table to the server, the server will still receive the copy of the original table with the string. I don’t know what’s happening to cause this, but at the time of destroying the element, the element is a string.
In fact, in 0.0.9, there was a Script for each Food-Thing, but now (0.0.26) I deleted theses Script to change into one single Script (that use 3 lines of codes), and it’s lighter now