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

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

Asked by 5 years ago

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)
0
Any errors? User#20989 0 — 5y
0
Your first argument to `onBatarangFired()` is the player object who fired the event, use that instead of LocalPlayer in your script Vulkarin 581 — 5y
0
It worked but now the BodyPosition doesn't take the object to mouse.Hit.p. Any ideas why? bruceywayne 35 — 5y
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. brokenrares 48 — 5y
View all comments (2 more)
0
How would I do that? I'm kinda of a beginner and I only worked with plr until now. bruceywayne 35 — 5y
0
Gave you an answer.Basically player will always be the first parameter but you can add another ones like I did below. brokenrares 48 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad

Answer this question