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)

6 comments
Any errors?
Your first argument to
onBatarangFired()is the player object who fired the event, use that instead of LocalPlayer in your scriptIt worked but now the BodyPosition doesn't take the object to mouse.Hit.p. Any ideas why?
That's because you need to pass the mouse.Hit.p as a parameter from the client to the server since the server can't 'see' the player's mouse.
How would I do that? I'm kinda of a beginner and I only worked with plr until now.
Gave you an answer.Basically player will always be the first parameter but you can add another ones like I did below.