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!
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. =)