So Basicly im a Beginner Developer that is making a game about Merging spheres but the game seems boring because all you do is merge Spheres so i decided to try and make a Value that goes up by +1 everytime the player merges 2 spheres (that are the same) so that i can make upgrades for players that will help them through the game. Only problem is that i dont exacly know how to, i used the AI feature, looked up on youtube and dev forums and guess what? Nothing! So i need help with Remote Events and Values.
You are editing the player’s value on the client. Anything changed on the client only changes for that client. You need to change it on the server for it to replicate.
FireClient takes one arguement minimum and that is the Player object of the player to fire to. You can use the Players service’s GetPlayerFromCharacter function to check for a player’s touch, or some other way to get the player.
Should look something like RemoteEvent:FireClient(player) and any other values to pass go after player as parameters.
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)
– Script for creating leaderstats for the player
– 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)