Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Filtering Enabled System doesn't work in-game. Any ideas why?

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

0

Any errors?

0

Your first argument to onBatarangFired() is the player object who fired the event, use that instead of LocalPlayer in your script

0

It worked but now the BodyPosition doesn't take the object to mouse.Hit.p. Any ideas why?

0

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.

0

How would I do that? I'm kinda of a beginner and I only worked with plr until now.

0

Gave you an answer.Basically player will always be the first parameter but you can add another ones like I did below.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.