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

Error "Unable to cast Instance to int"?

Asked by 7 years ago

I am trying to make a script that lets you get a award by using a chat command, and i'm using a RemoteEvent to do it. The problem is I get the " Unable to cast Instance to int" on line 8 of the second script.

LOCAL SCRIPT:

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://636749560"
local animtrack = nil
local canplay = true
local playe = game.Players.LocalPlayer
local char = playe.Character
local badgeid = 637991953
local id = playe.userId

local Lighting = game.Lighting
local Event = Lighting:WaitForChild("RemoteEvent")

function processCommand(message,recipient)
    if message == "/e dab" then
        print("part1")
        if canplay then
            canplay = false
            animtrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation)
            animtrack:Play()
        -- Call to the server
        -- We're going to give it some arguments that the AwardBadge function needs 
        -- So it needs the UserID and BadgeID
            Event:FireServer(playe.UserId, badgeid) -- Fires the arguments to the server
            print("event fired")
            canplay = true
        end
    end
end

playe.Chatted:connect(processCommand)

SERVER SCRIPT:

local badgeService = game:GetService("BadgeService")
-- Set up the RemoteEvent (It will be in Lighting)
local Lighting = game.Lighting
local Event = Lighting:WaitForChild("RemoteEvent")

function awardBadge(id, badgeid) -- The function in which awards the player
    print("awarding")
    badgeService:AwardBadge(id, badgeid) -- Awards the player - BOOM! :D
    print("awarded")
end

Event.OnServerEvent:connect(awardBadge) -- This listens to when the :FireServer() is called

Also, the tips are there because it was from someone who helped me earlier get this far. Thanks!

0
BTW Remote Event is already in lighting Tybearic 18 — 7y
0
On line 23 of the localscript, change 'playe.UserId' to 'id' and see what happens legosweat 334 — 7y
0
@qMeta It still doesn't work. Tybearic 18 — 7y
0
Possibly put the animation somewhere... so add a line after you give the animation its id and put 'animation.Parent = game.Players.LocalPlayer' legosweat 334 — 7y
View all comments (2 more)
1
Change the function to "badgeService:AwardBadge(-NEWLINE- id, -NEWLINE- badgeid)" to see wich part of the line errors. RubenKan 3615 — 7y
0
Line 23 should be userId Async_io 908 — 7y

1 answer

Log in to vote
0
Answered by
Async_io 908 Moderation Voter
7 years ago

Your coding is a bit strange, you're not using your variables as much as you should. I.e, you're defining things and not using them.

local animtrack
local canplay = true
local player = game.Players.LocalPlayer
player.CharacterAdded:connect(function(char)
    local animation = Instance.new("Animation")
    animation.AnimationId = "rbxassetid://636749560"
    animation.Parent = char
    animtrack = player.Character.Humanoid:LoadAnimation(animation) --Fixed
    local badgeid = 637991953
    local id = player.userId
    local Lighting = game.Lighting
    local Event = Lighting:WaitForChild("RemoteEvent")
    player.Chatted:connect(function(message,recipient)
        if string.lower(message) == "/e dab" then --this will have a better change of finding it
            print("part1")
            if canplay then
                canplay = false
                animtrack:Play()
                Event:FireServer(id, badgeid) -- Fixed
                print("event fired")
                canplay = true
            end
        end
    end)
end)
--This should work, but, assuming you have fe on, it will only show the animation for the player. To fix this, simply make and run the animation on the server script. =)
0
Thanks Tybearic 18 — 7y
0
I still get the same error though. Tybearic 18 — 7y
Ad

Answer this question