Let me start off this post by saying I want to achieve the firing of a client to server remote event (which spawns a model) for the ONLY player who touches a button and triggers the event.
I have been attempting to make an old-style tycoon game where every change is done with buttons. The issue stems from the beginning button a player presses in order to spawn their house. If I test the game with 5 people using Roblox’s emulator system and manually use each character to step on an individual button, it works fine.
However, when I use one character to step on multiple buttons, it spawns every single house all in the same place (so there are multiple copies, not just 1) and they are each assigned to every separate player.
Here is a screenshot of the game working correctly: (test with 4 characters)
Short video of the noted issue (again a test with 4 characters):
Video detailing the error.wmv (2.0 MB)
What have I tried thus far?
I originally thought it was an issue with my datastore, so I reworked my whole data store system… Twice. I first used regular data stores, then reworked with data store 2, then finally settled on using PlayerService.
I also thought the issue might be related to where I placed my remote events (ReplicatedStorage), as I heard that a remote event fired from the client will always fire for every player on the server. I tried moving my remote events into ServerStorage and workspace, with the same results happening each time.
My localscript (in StarterPlayerScripts):
local debounce = false
local homeOwnedCurrentSession = false
button1.Touched:Connect(function(otherPart)
if not debounce then
debounce = true
if homeOwnedCurrentSession == false then
homeOwnedCurrentSession = true
RemoteEvent1:FireServer()
print("event fired!")
else
print("you already own a home!")
end
end
end)
Note that there are FOUR more of these remote event triggers, each corresponding with their own buttons. So there are 5 remote events and 5 buttons total.
My ServerScript:
Players.PlayerAdded:Connect(function(player)
local pFolder = Instance.new("Folder", workspace)
pFolder.Name = player.UserId
local pButtonFolder = Instance.new("Folder")
pButtonFolder.Parent = ReplicatedStorage
pButtonFolder.Name = player.UserId
end)
RemoteEvent1.OnServerEvent:Connect(function(player)
local playerProfile = profileCache[player]
if playerProfile.Data.homeOwned == false then
print("homeOwned has been changed to true")
playerProfile.Data.homeOwned = true
home1Module:spawnBaseHome(player, Vector3.new(0,0,0), button1, sign1, homeCF1, signClean1)
for _, house in workspace[player.UserId]:GetChildren() do
if house.Name == "baseHome" then
playerProfile.Data.home = RBLXSerializer.Encode(house, true)
end
end
elseif playerProfile.Data.homeOwned == true then
local homeData = playerProfile.Data.home
local home = RBLXSerializer.Decode(homeData, true)
home.Parent = workspace[player.UserId]
home:PivotTo(homeCF1:GetPivot() + Vector3.new(0,0,0))
home1Module:changeSignButton(sign1, player, button1, signClean1)
end
end)
Note once again that there are 5 OnServerEvent triggers, each corresponding with their separate remoteEvent. I am also using 3 ModuleScripts. One to serialize the models, another for the ProfileService, and another to change the accompanying signs/handle cleanup for when a player leaves. If anyone would like to help and needs the ModuleScript information as well, let me know.
I have been dealing with this issue for quite some time and would be very thankful for any help. Thanks.