The gravity coil doesn’t work when it’s given to player from a server storage, but when I put it in StarterPack it works. The game pass script works, and I think when the script moves cloned tool something happens it doesn’t work. (I use gravity coil from ToolBox)
I can add gravity coil script if necessary.
Try disabling and re-enabling the gravity coil script after parenting it to player, it may run while it is cloned and not moved to anywhere yet
If it doesn’t work then add the gravity coil script and the script that clones it
are you trying to access server storage from the client?
client sided scripts cant access serverstorage
if this is your case, consider replicatedstorage
It would help us if you gave us the script(s), so we can evaluate any possible problems.
Showing the script would definitely help; but some stuff to check would be:
- You clone it into the right place, in the player
- You do not use a localscript, as that cannot access storage.
local Players = game:GetService("Players")
local Tool = script.Parent
local GravityAccelerationConstant = 9.81 * 20 -- For every 20 studs is one meter on ROBLOX. 9.81 is the common accepted acceleration of gravity per a kg on earth, and is used on ROBLOX
local PercentGravity = 0.25 -- Percentage of countered acceleration due to gravity by the coil.
-- @author Quenty
-- A rewritten gravity coil script designed for understanding and reliability
local function WaitForChild(Parent, Name, TimeLimit)
-- Waits for a child to appear. Not efficient, but it shoudln't have to be. It helps with debugging.
-- Useful when ROBLOX lags out, and doesn't replicate quickly.
-- @param TimeLimit If TimeLimit is given, then it will return after the timelimit, even if it hasn't found the child.
assert(Parent ~= nil, "Parent is nil")
assert(type(Name) == "string", "Name is not a string.")
local Child = Parent:FindFirstChild(Name)
local StartTime = tick()
local Warned = false
while not Child and Parent do
wait(0)
Child = Parent:FindFirstChild(Name)
if not Warned and StartTime + (TimeLimit or 5) <= tick() then
Warned = true
warn("Infinite yield possible for WaitForChild(" .. Parent:GetFullName() .. ", " .. Name .. ")")
if TimeLimit then
return Parent:FindFirstChild(Name)
end
end
end
if not Parent then
warn("Parent became nil.")
end
return Child
end
local function CallOnChildren(Instance, FunctionToCall)
-- Calls a function on each of the children of a certain object, using recursion.
FunctionToCall(Instance)
for _, Child in next, Instance:GetChildren() do
CallOnChildren(Child, FunctionToCall)
end
end
local function GetBricks(StartInstance)
-- Returns a list of bricks (will include StartInstance)
local List = {}
CallOnChildren(StartInstance, function(Item)
if Item:IsA("BasePart") then
List[#List+1] = Item;
end
end)
return List
end
--[[Maid
Manages the cleaning of events and other things.
API:
HireMaid() Returns a new Maid object.
Maid[key] = (function) Adds a task to perform when cleaning up.
Maid[key] = (event connection) Manages an event connection. Anything that isn't a function is assumed to be this.
Maid[key] = nil Removes a named task. If the task is an event, it is disconnected.
Maid:GiveTask(task) Same as above, but uses an incremented number as a key.
Maid:DoCleaning() Disconnects all managed events and performs all clean-up tasks.
]]
local MakeMaid do
local index = {
GiveTask = function(self, task)
local n = #self.Tasks+1
self.Tasks[n] = task
return n
end;
DoCleaning = function(self)
local tasks = self.Tasks
for name,task in pairs(tasks) do
if type(task) == 'function' then
task()
else
task:disconnect()
end
tasks[name] = nil
end
-- self.Tasks = {}
end;
};
local mt = {
__index = function(self, k)
if index[k] then
return index[k]
else
return self.Tasks[k]
end
end;
__newindex = function(self, k, v)
local tasks = self.Tasks
if v == nil then
-- disconnect if the task is an event
if type(tasks[k]) ~= 'function' and tasks[k] then
tasks[k]:disconnect()
end
elseif tasks[k] then
-- clear previous task
self[k] = nil
end
tasks[k] = v
end;
}
function MakeMaid()
return setmetatable({Tasks={},Instances={}},mt)
end
end
local function GetCharacter(Descendant)
-- Returns the Player and Charater that a descendent is part of, if it is part of one.
-- @param Descendant A child of the potential character.
local Charater = Descendant
local Player = Players:GetPlayerFromCharacter(Charater)
while not Player do
if Charater.Parent then
Charater = Charater.Parent
Player = Players:GetPlayerFromCharacter(Charater)
else
return nil
end
end
-- Found the player, character must be true.
return Charater, Player
end
--- Load and create constants
local AntiGravityForce = Instance.new("BodyForce")
AntiGravityForce.Name = "GravityCoilEffect"
AntiGravityForce.Archivable = false
local Handle = WaitForChild(Tool, "Handle")
local CoilSound = WaitForChild(Handle, "CoilSound")
local GravityMaid = MakeMaid() -- Will contain and maintain events
local function UpdateGravityEffect(Character)
-- Updates the AntiGravityForce to match the force of gravity on the character
local Bricks
if Character:IsDescendantOf(game) and Character:FindFirstChild("HumanoidRootPart") and Character.HumanoidRootPart:IsA("BasePart") then
local BasePart = Character.HumanoidRootPart
Bricks = BasePart:GetConnectedParts(true) -- Recursive
else
warn("[UpdateGravityEffect] - Character failed to have a HumanoidRootPart or something")
Bricks = GetBricks(Character)
end
local TotalMass = 0
-- Calculate total mass of player
for _, Part in pairs(Bricks) do
TotalMass = TotalMass + Part:GetMass()
end
-- Force = Mass * Acceleration
local ForceOnCharacter = GravityAccelerationConstant * TotalMass
local CounteringForceMagnitude = (1 - 0.25) * ForceOnCharacter
-- Set the actual value...
AntiGravityForce.force = Vector3.new(0, CounteringForceMagnitude, 0)
end
-- Connect events for player interaction
Tool.Equipped:connect(function()
local Character, Player = GetCharacter(Tool)
if Character then
-- Connect events to recalculate gravity when hats are added or removed. Of course, this is not a perfect solution,
-- as connected parts are not necessarily part of the character, but ROBLOX has no API to handle the changing of joints, and
-- scanning the whole game for potential joints is really not worth the efficiency cost.
GravityMaid.DescendantAddedConnection = Character.DescendantAdded:connect(function()
UpdateGravityEffect(Character)
end)
GravityMaid.DecendantRemovingConnection = Character.DescendantRemoving:connect(function()
UpdateGravityEffect(Character)
end)
UpdateGravityEffect(Character)
-- Add in the force
AntiGravityForce.Parent = Handle
else
warn("[GravityCoil] - Somehow inexplicity failed to retrieve character")
end
end)
Tool.Unequipped:connect(function()
-- Remove force and clean up events
AntiGravityForce.Parent = nil
GravityMaid:DoCleaning()
end)`Preformatted text`
type or paste code here
game.Players.PlayerAdded:Connect(function(player) -- i aint readin allat
player.CharacterAdded:Connect(function(character)
if not game.MarketplaceService:UserOwnsGamePassAsync(player.UserId, the gamepass id) then return end
game.ServerStorage.urtoolsnamelol:Clone().Parent = player.Backpack
end)
end)
Okay I tried from server-side script and it somehow worked.
Local Script
local MarketplaceService = game:GetService("MarketplaceService")
function onPromptPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess and purchasedPassID == 000000000 then
game.ReplicatedStorage.GamePasses:FireServer("gravityCoil")
end
end
script.Parent.MouseButton1Click:Connect(function()
game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, )
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptPurchaseFinished)
end)
Script
game.ReplicatedStorage.GamePasses.OnServerEvent:Connect(function(plr, gamepass)
if gamepass == "gravityCoil" then
local tool = game.ServerStorage["Gravity Coil"]:Clone()
tool.Parent = plr.Backpack
end
end)
Didn’t you say that the gravity coil script didn’t work, when it was given to a player from Server Storage
?
Did you change something from last time, that made this solution work?
Yes, I changed the whole script that clone the tool and it worked.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.