I have a tool in replicatedstorage that goes in the player’s backpack when they purchase the item and some scripts inside. When you click to throw the ball, it is not throwing or doing anything. Here is my explorer: (In replicatedstorage)
BallServer:
local tool = script.Parent
local re = tool:WaitForChild("BallRE")
local cooldown = false
local ps = game:GetService("PhysicsService")
ps:CreateCollisionGroup("Ball")
ps:CreateCollisionGroup("Character")
ps:CollisionGroupSetCollidable("Character", "Ball", false)
re.OnServerEvent:Connect(function(plr, mouseHit)
local char = plr.Character
local hum = char:FindFirstChild("Humanoid")
if hum and not cooldown then
cooldown = true
hum.Jump = true
local ballClone = tool.Handle:Clone()
ballClone.Transparency = 0
tool.Handle.Transparency = 1
for i, descendant in pairs(plr.Character:GetDescendants()) do
if descendant:IsA("BasePart") then ps:SetPartCollisionGroup(descendant, "Character") end
end
ps:SetPartCollisionGroup(ballClone, "Ball")
local velocity = mouseHit.Position + Vector3.new(0, game.Workspace.Gravity * 0.5, 0)
ballClone.Velocity = velocity
ballClone.CanCollide = true
ballClone.Parent = workspace
game:GetService("Debris"):AddItem(ballClone, 2)
wait(3)
ballClone.Velocity = Vector3.new(0, 0, 0)
tool.Handle.Transparency = 0
cooldown = false
end
end)
BallClient:
local tool = script.Parent
local re = tool:WaitForChild("BasketballRE")
local mouse = game.Players.LocalPlayer:GetMouse()
tool.Activated:Connect(function()
re:FireServer(mouse.Hit)
end)
I checked for errors and didn’t see any. The issue is that when you click it doesn’t throw the ball or anything but if I put the ball in workspace and just pick it up like that it works but if I put it in replicatedstorage and the player purchases it and tries to use it it doesn’t throw when you click it
oh uh oops I’ll try that when I can and let yk if it works
It was a basketball and then I wanted it to be a beach ball and I forgot to change the name so that’s why
Thats what I changed but it still doesn’t work
Also it worked before when I put the tool in workspace, picked it up and tried it but now when I want it to be purchased and parented to the backpack when its purchased it doesn’t seem to be working
Can you provide the script for purchasing the ball and giving it to the player? The problem might be in there and not the throwing script, if it works when the player picks it up from the workspace.
Okay so for purchasing there is a LocalScript inside the purchase button and here it is (Shells is my game’s currency)
:
local player = game.Players.LocalPlayer
local Ball = game.ReplicatedStorage["Beach Ball"]:Clone()
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Shells.Value >= 150 then
-- Checks if player has enough shells
game.Workspace.PurchaseSuccessful:Play()
game.ReplicatedStorage.PurchaseBall:FireServer(150)
-- Fires RemoteEvent that charges player
Ball.Parent = player.Backpack
else
game.Workspace.PurchaseFailed:Play()
script.Parent.Text = ("Insufficient funds!")
wait(3)
script.Parent.Text = ("Purchase for 150 Shells...")
end
end)
In ReplicatedStorage, there is a RemoteEvent called PurchaseBall.
In ServerScriptService, there is a script that handles all the things that charge the player. I have all my purchases in this script, but I’ll show the ball one as well as a screenshot if you want the entire script.
Here is the link to the article if you need it. The problem might also possibly be that you are putting the tool inside the backpack from a local script and not a server script.
I noticed that when I equip the tool it goes out of my players backpack and back in when I unequip it. Could this have anything to do with the problem considering the scripts are in that tool?
Not equipped:
It does seem strange that the ball is removed from the backpack when equipped. Maybe try moving the BallServer script to ServerScriptService and editing the line that finds the ball accordingly.