OnServerEvent string expected got instance error for data

error Line 5: invalid argument #2 string expected got instance

someone have an idea why this onServerEvent is not working?

note: i have this system working in another script. the difference is i’m getting player from a touched event vs sending through fireServer.

local potionEvent = game.ReplicatedStorage.remoteEvents.potionEvent
local data = game.ServerScriptService.Server.data

potionEvent.OnServerEvent:Connect(function(player)
    data[player].hasFullHealthPotion = false
    player.Character.Humanoid.Health = 100
    print(player.Name .. ' took a full health potion and now has 100 health :)')
end)

here’s data

local data = {}

game.Players.PlayerAdded:Connect(function(player)
    data[player] = {}
    data[player].canHurt = true

    --// potions
    data[player].hasHalfHealthPotion = false
    data[player].hasFullHealthPotion = true
    data[player].hasSpeedPotion = false
end)

return data

Just to confirm, the error lies on this line of code, right?

yeah. oh i edited the description so it’s line 5.

data[player].hasFullHealthPotion = false

Module scripts don’t run unless required by another script.

In this line, you’re only referring that module script but not requiring any contents of it, so you should use require() upon that module script.

2 Likes

omg that’s the second time i’ve done that this week lmfao. i just forget to use require. thanks bro.

1 Like