touched script
script.Parent.Touched:Connect(function() local Players = game.Players local part = script.Parent local player = Players:GetPlayerFromCharacter(part.Parent) game.ReplicatedStorage:WaitForChild("PurchaseZone"):Fire(player,script.Parent.Name,10) end)
I am working on a game, i am trying to pass the player who touched a certain brick to another script but it returns a nil value, i tried getplayerfromcharacter but no success, any other methods?
receiver
game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = Player local zones = Instance.new('Folder') zones.Name = "Zones" zones.Parent = Player local candy = Instance.new("IntValue") candy.Name = "Candy" candy.Parent = leaderstats candy.Value = 10 local currenttool = Instance.new("Folder") currenttool.Name = "CurrentTool" currenttool.Parent =Player local testzone = Instance.new("StringValue") testzone.Name = "Partt" testzone.Value = "Partt" testzone.Parent = zones end) game.ReplicatedStorage.PurchaseZone.Event:Connect(function(player,zone,cost) if player.Zones:GetChildren().Name ~= zone and player.leaderstats.Candy.Value >= cost then local zoneadded = Instance.new("StringValue") zoneadded.Parent = player.Zones zoneadded.Name = zone zoneadded.Value = zone end end)
I've made some changes, you are trying to get the character from script.Parent but instead you should be using the parent of the touching part itself given from the Touched event
script.Parent.Touched:Connect(function(part) local Players = game.Players local player = Players:GetPlayerFromCharacter(part.Parent) if player then game.ReplicatedStorage:WaitForChild("PurchaseZone"):Fire(player,script.Parent.Name,10) end end)