Im not the smartest guy but this is what its giving me an error that doesn’t allow the script to progress:
Script(inside of the sphere):
local SS = game:GetService(“ReplicatedStorage”)
local MergeSound = workspace[“Music/Sounds”]:FindFirstChild(“MergeSound”)
local player = game.Players:GetPlayerFromCharacter() – What gives me the error
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Name == "Orbie1" then
game.ReplicatedStorage.MergeStatEvent:FireClient(player)
MergeSound:Play()
part:Destroy()
hit:Destroy()
local newPart = SS.Orbies.Orbie2:Clone()
newPart.Parent = workspace
newPart.Position = hit.Position
end
end)
– Get the player’s character
local function onPlayerAdded(player)
local character = player.Character or player.CharacterAdded:Wait()
– Wait for the player’s humanoid to load
local humanoid = character:WaitForChild(“Humanoid”)
– Create leaderstats for the player
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
– Create a value for the player’s money
local money = Instance.new(“IntValue”)
money.Name = “Merged”
money.Value = 0
money.Parent = leaderstats
There is no local player, so you will have to add like local Players = game:GetService:("Players).
You can use this code instead of that, remote events is not your best bet.
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Name == "Orbie1" then
money.Value = money.Value + 1
MergeSound:Play()
part:Destroy()
hit:Destroy()
local newPart = SS.Orbies.Orbie2:Clone()
newPart.Parent = workspace
newPart.Position = hit.Position
end
end)
That is how you get the player when they touched a part and using the Fire Client.
It seems like the script works only for the merging part but now i gotta figure out how to get the leaderstats as the leaderstats dont appear, doing nothing in the process
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Name == "Orbie1" then
local Players = game:GetService("Players")
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.leaderstats.money.Value = player.leaderstats.money.Value + 1
end
MergeSound:Play()
part:Destroy()
hit:Destroy()
local newPart = SS.Orbies.Orbie2:Clone()
newPart.Parent = workspace
newPart.Position = hit.Position
end
end)
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Name == "Orbie1" then
local Players = game:GetService("Players")
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.leaderstats.Merged.Value = player.leaderstats.Merged.Value + 1
end
MergeSound:Play()
part:Destroy()
hit:Destroy()
local newPart = SS.Orbies.Orbie2:Clone()
newPart.Parent = workspace
newPart.Position = hit.Position
end
end)
It doesn’t work because the value is an Integer/Int Value, It only accepts for Positive and Negative Numbers, you will have to replace the Instance.new(“IntValue”) to Instance.new(“NumberValue”). Here is your updated script for the leaderstats.
Its still not doing anything, for a bit of context. What the player needs to do is push the sphere to the other one, when the sphere touches the other one then it will create a new variant and it WOULD give the value if it did anything.
local part = script.Parent
part.Touched:Connect(function(hit)
print(hit.Name)
if hit.Name == "Orbie1" then
local Players = game:GetService("Players")
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.leaderstats.Merged.Value = player.leaderstats.Merged.Value + 1
end
MergeSound:Play()
part:Destroy()
hit:Destroy()
local newPart = SS.Orbies.Orbie2:Clone()
newPart.Parent = workspace
newPart.Position = hit.Position
end
end)
I have solved it! i made a server script where instead of the leaderstats folder being in the player, i made it in the replicated storage then i made a gui where the localscript will count how much Points you have, then i only needed to add a single line of code for the orbies and i was done!