Hey. I want to make a Throw-able Object System that when I press R an animation plays and an object goes to where I point. The problem is it works in studio but not in-game. Those are the scripts:
Script:
math.randomseed(tick()) local ServerStorage = game:GetService("ServerStorage") local ReplicatedStorage = game:GetService("ReplicatedStorage") local BatarangEvent = Instance.new("RemoteEvent", ReplicatedStorage) BatarangEvent.Name = "BatarangEvent" local animations = {2174439989} local function onBatarangFired(plr) local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Batarang = ServerStorage:WaitForChild("Batarang") local character = game.Workspace:FindFirstChild(plr.Name) local MoveToFire = character:WaitForChild("Chest1"):WaitForChild("Part") local humanoid = character:WaitForChild("Humanoid") local ToBeUsedAnimation = Instance.new("Animation") local picked = math.random(1, #animations) ToBeUsedAnimation.AnimationId = "http://roblox.com/asset/?id="..animations[picked] local animTrack = humanoid:LoadAnimation(ToBeUsedAnimation) animTrack:Play() local UsedBatarang = Batarang:Clone() UsedBatarang.Parent = game.Workspace UsedBatarang.Orientation = MoveToFire.Orientation UsedBatarang.Position = MoveToFire.Position UsedBatarang.Anchored = true humanoid.WalkSpeed = 0 UsedBatarang.Anchored = false local b = Instance.new("BodyPosition") b.Name = "ActualPosition" b.Parent = UsedBatarang b.MaxForce = Vector3.new(500000000, 500000000, 500000000) b.Position = mouse.Hit.p b.D = 1000 humanoid.WalkSpeed = 16 wait(5) UsedBatarang:Destroy() end BatarangEvent.OnServerEvent:Connect(onBatarangFired)
Local Script:
local UserInputService = game:GetService("UserInputService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local character = game.Players.LocalPlayer.Character local BatarangEvent = ReplicatedStorage:WaitForChild("BatarangEvent") local ready = true local function batarang(inputObject, gameProcessed) if inputObject.KeyCode == Enum.KeyCode.R and ready then BatarangEvent:FireServer() ready = false wait(.5) ready = true end end UserInputService.InputBegan:Connect(batarang)
Answer to my comment:
Local script
local UserInputService = game:GetService("UserInputService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local character = game.Players.LocalPlayer.Character Player = game.Players.LocalPlayer mouse = Player:GetMouse() local BatarangEvent = ReplicatedStorage:WaitForChild("BatarangEvent") local ready = true local function batarang(inputObject, gameProcessed) if inputObject.KeyCode == Enum.KeyCode.R and ready then local mousehitp = mouse.Hit.p BatarangEvent:FireServer(mousehitp) ready = false wait(.5) ready = true end end UserInputService.InputBegan:Connect(batarang)
Script
math.randomseed(tick()) local ServerStorage = game:GetService("ServerStorage") local ReplicatedStorage = game:GetService("ReplicatedStorage") local BatarangEvent = Instance.new("RemoteEvent", ReplicatedStorage) BatarangEvent.Name = "BatarangEvent" local animations = {2174439989} local function onBatarangFired(plr, mousehitp) local Batarang = ServerStorage:WaitForChild("Batarang") local character = game.Workspace:FindFirstChild(plr.Name) local MoveToFire = character:WaitForChild("Chest1"):WaitForChild("Part") local humanoid = character:WaitForChild("Humanoid") local ToBeUsedAnimation = Instance.new("Animation") local picked = math.random(1, #animations) ToBeUsedAnimation.AnimationId = "http://roblox.com/asset/?id="..animations[picked] local animTrack = humanoid:LoadAnimation(ToBeUsedAnimation) animTrack:Play() local UsedBatarang = Batarang:Clone() UsedBatarang.Parent = game.Workspace UsedBatarang.Orientation = MoveToFire.Orientation UsedBatarang.Position = MoveToFire.Position UsedBatarang.Anchored = true humanoid.WalkSpeed = 0 UsedBatarang.Anchored = false local b = Instance.new("BodyPosition") b.Name = "ActualPosition" b.Parent = UsedBatarang b.MaxForce = Vector3.new(500000000, 500000000, 500000000) b.Position = mousehitp b.D = 1000 humanoid.WalkSpeed = 16 wait(5) UsedBatarang:Destroy() end BatarangEvent.OnServerEvent:Connect(onBatarangFired)