Script doesn't work well, how can i make it better

Hello! I am Dev_Asher and I am working on a find the markers game remake, I made a script where when the player touched a marker or in this case a Bunny, it fires a remote event to the client where it will reward the player for finding the Bunny. But the icon won’t show as the bunny that was touched, for example, if I were to touch a Grey bunny it would show it correctly but then if I were to touch a purple bunny, it would show the grey bunny again. How would I fix this?

here is the script

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')

local BunnyFolder = workspace:WaitForChild('BunnysFolder')

local ReplicatedModules = require(ReplicatedStorage:WaitForChild('Modules'))
local RemoteModule = ReplicatedModules.RemoteService
local BunnysModule = ReplicatedModules.Bunnys

local SystemsContainer = {  }
local Debounce = {  }

local BunnyTouchedEvent : RemoteEvent = RemoteModule:GetRemote('BunnyTouched', 'RemoteEvent', false)

local selectedData = nil

local Module = {}

function Module:BunnyStack(BunnyID)
	return {
		ID = BunnyID,
		UUID = HTTPService:GenerateGUID(false)

function Module:SetProperties(parent, propertiesTable, name)
	local title = parent:FindFirstChild("Title")
	local icon = parent:FindFirstChild("Icon")
	if icon then 
		icon.Image = propertiesTable.Display.Icon
	if title then
		title.Text = propertiesTable.Display.Title.Text

local DB = false
function Module:CheckBunnyFromID(BunnyID, BunnyName)	
	for i, Bunny in pairs(BunnyFolder:GetChildren()) do
		if Bunny:IsA('Part') and Bunny.Parent == BunnyFolder then
				if DB == false then DB = true
					local LocalPlayer = Players:GetPlayerFromCharacter(Hit.Parent)
					BunnyTouchedEvent:FireClient(LocalPlayer, Bunny)
					local Interface = LocalPlayer:WaitForChild('PlayerGui'):WaitForChild('Ui_Interface')
					local FoundBunnyUI = Interface:WaitForChild('BunnyFound')
					local LHUD = Interface:WaitForChild('LHUD')

					local selectedConfig = selectedData and BunnysModule:GetItemConfig(selectedData.ID)

					Module:SetProperties(FoundBunnyUI, BunnyID, BunnyName)
					LHUD.Visible = false
					FoundBunnyUI.Visible = true
					FoundBunnyUI.Visible = false
					FoundBunnyUI.Icon.Image = 'rbxassetid://4617621496'
					LHUD.Visible = true
					DB = false
			warn('Touched Part Not From Bunny Folder')

function Module:Init(otherSystems)

	SystemsContainer = otherSystems


return Module

Maybe the variable for the gui didn’t change?

How would I change it? Also FYI I have another module that has the icon ID’s

Change the gui on from the remote event on the local side

With a local script inside starter gui or starter player scripts

Cause you fire a remote event and it’s intercepted by a local script. Change the gui in that local script from the remote.

Where would I put this Local Script?

I don’t understand, so you fired an remote event from the server to the client right? You can change the gui on the client.
Also you should always reward the player on the server if you want data to save or unless you are transferring data from the client to the server which will take more work.

But how would I change the gui to the client, I only have a module script and a server script that fires the function in the Module

The module script is the one i sent you.

Don’t you have a local script?

BunnyTouchedEvent.OnClientEvent:Connect(function(--) --Put information that it recieves in parameters
	--Change gui

1 Like

nope sorry i will make it right now.

1 Like

Also you can compare the bunny name to find out it’s correct id icon. Then you set the icon that should be showing. This can be done by using an if statement in the local script.

1 Like

Ok thank you, I am good with server side but I need to get better at client side.

1 Like

No problem. Good Luck with your game and don’t give up when you are stuck!

1 Like

I am now getting this error FireClient: player argument must be a Player object - Server - MainBunny:47

So on the server side? Well, try this

BunnyTouchedEvent:FireClient(player, Bunny)

The first parameter is always player, cause you need to know the player that fired it

so in the server script that calls the functions

Yes but which script do i put this line of code in?

The one that fires the remote in the first place.